Techmate Posted August 24, 2012 Share Posted August 24, 2012 The problem that I am having is rather simple it seems but I am a little stumped I have been working on it for 2 days now :-\. As you see below it querys 217 two times and I just need it to query all the results only once. Any idea why??? SELECT id id, cast.booked booked FROM images, cast WHERE id = cast.memberid AND posterid = '51' UNION SELECT memberid id, images.booked booked FROM cast,images WHERE posterid='51' AND null !='' ORDER BY id ASC id | booked --------------- 217 217 yes 218 219 yes Quote Link to comment Share on other sites More sharing options...
Christian F. Posted August 24, 2012 Share Posted August 24, 2012 What you want to use is a JOIN, not a UNION statement. Quote Link to comment Share on other sites More sharing options...
Techmate Posted August 24, 2012 Author Share Posted August 24, 2012 I have tried that and are getting the same results. SELECT distinct memberid, id, cast.booked FROM images, cast WHERE memberid = images.id AND posterid = '51' Quote Link to comment Share on other sites More sharing options...
Techmate Posted August 24, 2012 Author Share Posted August 24, 2012 What you want to use is a JOIN, not a UNION statement. Omg I started with a join query then moved on to UNION and you were right Join worked all I had to do is GROUP BY end LOL. THANKS! Quote Link to comment Share on other sites More sharing options...
Christian F. Posted August 24, 2012 Share Posted August 24, 2012 You're welcome, and I'm glad I could help. Though, please use explicit JOIN statements, not implicit ones like the above. Doing it the right way will make the query a lot easier to read, and thus maintain. Saving you a lot of future headaches. Quote Link to comment 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.