Mysql
 SQL >> Database >  >> RDS >> Mysql

Selezionare righe da più tabelle con UNION

Se le tabelle hanno la stessa struttura, puoi usare una sola query UNION.

SELECT *, 'text' AS src FROM text WHERE keyword='$string'
UNION
SELECT *, 'sticker' AS src FROM sticker WHERE keyword='$string'
UNION
SELECT *, 'image' AS src FROM image WHERE keyword='$string';

La colonna src indica l’origine della riga.