Mysql
 sql >> Database >  >> RDS >> Mysql

Joining Table con condizione di sottostringa

Prova

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

e SELEZIONA

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

Uscita:

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

SQLFiddle