Jump to content

[SOLVED] Query Help


jaymc

Recommended Posts

I want to retreive 2 rows of data from 1 table but with different WHERE clause basically

 

Here is what a row may look like

 

 

id - user - time - valid

12 - Jamie - 12312312423 - 2

15 - Jamie - 12315898973 - 0

14 - Jamie - 12389759578 - 1

 

I want to have 1 query return all rows:

"WHERE user = Jamie AND valid = 1 LIMIT 0,1"

AND

"WHERE user = Jamie AND time > 25000 LIMIT 0,1"

 

This should give me

 

12 - Jamie - 20000 - 2

12 - Jamie - 30000 - 1

 

What is the best way to do this without pulling out all the DATA and using PHP to find the matches, aswell as using 2 queries

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/85162-solved-query-help/
Share on other sites

Actually seeing your code you can do it in one query

 

select * from ...
WHERE user = Jamie AND (valid = 1 OR time > 25000) LIMIT 2

 

not too sure it will work tho just a thought

Yes, but depending on which version of mysql you're using and what indexes your have, this may or may not be more efficient.

Link to comment
https://forums.phpfreaks.com/topic/85162-solved-query-help/#findComment-434560
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.