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
https://forums.phpfreaks.com/topic/238822-union-join-or/
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.