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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.