Hello I have these 4 tables with the structure
Table: Users [ id, username, password, bouquet_id ]
Table: Bouquets [ id, bouquet_name, stream_ids = serialized array ]
Table: Streams [ id, channel_name ]
Table: activity [ id, user_id, stream_id ]
I want to select ALL users but with their info as well from other tables + THE LAST ROW from table activity per user
For example the following query:
SELECT t1.*,t2.`bouquet_name`
FROM `users` t1,`bouquets` t2
WHERE t1.`bouquet_id ` = t2.`id`
ORDER BY t1.id DESC
Takes the data from the first 2 tables and assigned the bouquet_id to its bouquet name. Now i want to have in query the last ROW from activity table WITH it's stream name [based on stream_id]
The following query does the job i want[ PER USER]
SELECT t1.channel_name
FROM `streams` t1,`activity` t2
WHERE t2.user_id = **'%d'** AND t1.id = t2.stream_id
ORDER BY t2.id DESC
LIMIT 1
But its a kind slow since for every user in the table "users" i run 2 queries. I want the 2 queries above to be embed together as one so that i will be able to select the data from the first two tables BUT WITH the last row from table activity based on user_id.
Hope you understand me thank you