This is my tables and structure
Shoutbox
- SID //PK
- Title //Title
shoutbox_follower
- SID
- UID //User ID
Shouts
- SID
- Text //Shouts
I want to get the last 1 (latest) shouts(Shouts.Text) for each Shoutbox, which the user is following
i tried this but it did not worked
select shoutbox_follower.SID,shoutbox.title, shouts.text from shoutbox_follower, shoutbox, shouts where shoutbox_follower.uid=1;
But i can do the work with multiple query
SELECT SID from shoutBox_Follower where UID=5
SELECT SID,TEXT from Shouts where SID in ($boxList) order by id desc limit 1
SELECT Title from Shoutbox where SID=? limit 1
You can combine the queries, in cases like this:
It performs very fast for small numbers of rows (assuming you’ve the needed indexes, of course). Based on your third query, the title can be fetched using a simple inner join.