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

UNION dopo ORDER BY e LIMIT

Puoi usare le parentesi per consentire l'uso di ORDER /LIMIT su singole domande:

(SELECT * FROM some tables WHERE ... ORDER BY field1 LIMIT 0, 1)
UNION   
(SELECT * FROM some tables WHERE ...)
ORDER BY 1   /* optional -- applies to the UNIONed result */
LIMIT 0, 100 /* optional -- applies to the UNIONed result */