PDA

View Full Version : [SQL] Select from 3 identical tables?



Moh
10-09-2010, 04:11 PM
I rarely create complex sqls and ain't done a join for years.

I can get two tables to join, but not 3.

+rep to any help :)

LMS16
10-09-2010, 06:18 PM
Can you expand on what you want?

Wouldnt you use the distinct? Havent used it personally but I think you need to use that :)

Lew.

Moh
10-09-2010, 06:20 PM
So far I have:


SELECT comments.id FROM comments c INNER JOIN group_comments g ON c.id = g.id JOIN photo_comments p ON g.id = p.id

But that ain't working

LMS16
10-09-2010, 08:58 PM
I prefer to stick to simple sql commands if poss lol. But I think it wud be work checking out the distinct command?

Lew.

Blob
10-09-2010, 09:04 PM
So far I have:


SELECT comments.id FROM comments c INNER JOIN group_comments g ON c.id = g.id JOIN photo_comments p ON g.id = p.id

But that ain't working

Try this


SELECT * FROM ( comments LEFT JOIN group_comments ON comments.id = group_comments.id ) LEFT JOIN photo_comments ON group_comments.id = photo_comments.id

Moh
10-09-2010, 09:09 PM
Try this


SELECT * FROM ( comments LEFT JOIN group_comments ON comments.id = group_comments.id ) LEFT JOIN photo_comments ON group_comments.id = photo_comments.id
Tried that too =[

In the end i just used UNION :)

Want to hide these adverts? Register an account for free!