I want to show the user last activity. (you can read my last question for more info about it)
I need to do a big JOIN (6+ tables).
I need to get only one row per ID but there are some tables that contain more than one row per ID. For example an article ID can have only one row in the 'votes' table but it can have a lot in the 'images' table because there can be more than one image per article, but I want just one image.
So I need to do something like this (of course this code is wrong):
SELECT table1.item, table2.item, table3.item, table4.item, table5.item
FROM table1
LEFT OUTER JOIN ... ON ... AND ...
LEFT OUTER JOIN ... ON ... AND ...
LEFT OUTER JOIN ... ON ... AND ... LIMIT 1
LEFT OUTER JOIN ... ON ... AND ... LIMIT 1
WHERE table1.item = ?;
How can I accomplish that?
This is similar to http://dev.mysql.com/doc/refman/5.1/en/example-maximum-column-group-row.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With