2

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

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

My version of mysql doesn't support limit & in/all/any/some subquery... Any other ideas?
Don't use a LIMIT at all in the subquery then, simply limit your outer result set. PS. What version of MySQL are you using?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.