如何在 SQL 子查询中返回多个结果?
我在下面有一个查询,想知道是否可以获得超过 1 个结果。我想要获取 4 个最新条目。
谢谢!
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
I have a query below and would like 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
IN
而不是=
:也不要将子查询限制为
LIMIT 1
。您需要在子查询中使用LIMIT 4
。Use
IN
instead of=
:Also don't limit your subquery to
LIMIT 1
. You'll needLIMIT 4
in the sub-query.