How do I return multiple results in a SQL subquery?
I have a query below and would li开发者_如何学运维ke to know if it is possible to get more than 1 result. I would like to get the 4 most recent entries.
Thanks!
select c.email,c.text,m.alertDataID
from client_users as c, monitor_alerts as a, monitor_alerts_data as m
where c.id=a.userID and a.alertID=m.alertID and
m.alertDataID = (SELECT alertDataID FROM monitor_alerts_data ORDER BY alertDataID DESC LIMIT 1)
LIMIT 4
Use IN
instead of =
:
... and m.alertDataID IN (SELECT alertDataID FROM ...)
Also don't limit your subquery to LIMIT 1
. You'll need LIMIT 4
in the sub-query.
精彩评论