sql >> Base de Datos >  >> RDS >> Mysql

Unión de tabla con condición de subcadena

Prueba

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

y SELECCIONAR

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

Salida:

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

SQLFiddle