开发者

How do I return multiple results in a SQL subquery?

开发者 https://www.devze.com 2023-01-18 16:35 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消