Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Joining-Tabelle mit Teilstring-Bedingung

Versuchen Sie es

UPDATE t1 LEFT JOIN t2
    ON t1.`group` = LEFT(t2.number, 3)
   AND t1.number = 0 + RIGHT(t2.number, 5)
   SET t1.used = 'NO'
 WHERE t2.id IS NULL

und AUSWÄHLEN

SELECT *
  FROM t1 LEFT JOIN t2
    ON t1.`group` = LEFT(t2.number, 3)
   AND t1.number = 0 + RIGHT(t2.number, 5)
 WHERE t2.id IS NULL

Ausgabe:

| ID | GROUP | NUMBER | USED |
------------------------------
|  3 |   110 |      3 |   NO |
|  4 |   210 |      1 |   NO |
|  6 |   210 |      3 |   NO |

SQLFiddle