Jump to content

Union, Join, or?


SharkBait

Recommended Posts

Can't seem to quite figure out what query I need to do what I want.

 

SELECT IFNULL(id, 0) as id1 FROM photo WHERE id < 3 LIMIT 1
UNION
SELECT IFNULL(id, 0) as id2 FROM photo WHERE id > 3 LIMIT 1

 

Essentially I want to return 2 columns, the first one being from the top query and the second one for hte bottom query. But then a union isn't what i want is it?

 

Then i tried to do a join

SELECT t1.id as id1, It2.id as id2
FROM photo as t1
JOIN photo as t2 
WHERE t1.id > 2 AND t2.id < 2

 

But that didn't work either..

What is it I am looking for?

Trying to return the the row before and after a particular entry with 1 query as opposed to 2.

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.