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

Come posso concatenare interi set di risultati in MySQL?

Forse dovresti provare a includere una quarta colonna, indicando la tabella da cui proviene, quindi ordinare e raggruppare in base ad essa:

SELECT A,B,C, "query 1" as origin FROM table WHERE field LIKE 'query%'
UNION
SELECT A,B,C, "query 2" as origin FROM table WHERE field LIKE '%query'
UNION
SELECT A,B,C, "query 3" as origin FROM table WHERE field LIKE '%query%'
GROUP BY origin, B ORDER BY origin, B ASC LIMIT 5