Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Unindo a tabela com condição de substring


Tentar
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 SELECIONE
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

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

SQLFiddle