SharkBait Posted June 8, 2011 Share Posted June 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238822-union-join-or/ Share on other sites More sharing options...
requinix Posted June 8, 2011 Share Posted June 8, 2011 Subqueries. SELECT IFNULL((SELECT id FROM photo WHERE id IFNULL((SELECT id FROM photo WHERE id > 3 ORDER BY something besides the id number ASC LIMIT 1), 0) AS id2 Quote Link to comment https://forums.phpfreaks.com/topic/238822-union-join-or/#findComment-1227177 Share on other sites More sharing options...
SharkBait Posted June 8, 2011 Author Share Posted June 8, 2011 Awesome.. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/238822-union-join-or/#findComment-1227181 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.