If its taking a long time to execute, that is an indication of incorrect indexes being set.
So status_linkes.status_id and statuses.id must both be the same datatype and have the same definition, and then make sure both are indexed for faster lookups. You'll never get the same performance as just a single table query, but you shouldn't see a substantial increase either. Also make sure that the nick field on statuses is indexed, but given the 'nick' name for it, that would indicate to me that it's already likely indexed as a unique (but no guarantee since the table name itself doesn't tell me that it has to be unique).
As for the output, that is what you'll get. The language is responsible for formatting it in another logical way. MySQL has a group_concat function that lets you join multiple child records into a single field, but I personally think that's among one of the sillier functions available.
I need select * from statuses LIMIT 30 ... then make a select from status_likes (on one status can be many likes) ...AND SELECT XY likes from status_likes .... where the status_likes.status_id will be the statuses.id ... so
- select 30 statuses
- select XY status likes on this 30 status id.
? :P Everyone who would help i would be so happy !
Show us your COMPLETE table schemas. That is, all the fields and their types for both tables. And if fields are related to one another, show that as well.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Okay ... here are my tables what i need ( i changed my problem so please forget on the previous (its similiar) but lets look at this problem ... how would u solved it? :P )
I have array with this ID of statuses (3398,3342,3129,2895,2157,2072,2062,1995,1945,1915) so i think we can use IN later...
Now i need withdraw all comments from comments table where comments.status_id are from this array with ids...
Then i need select from another table (where the users are) the profile_picture_ultra_small... and connect it with the comments nick names
what is important... its there can be a lot of statuses to one status id ... and just one picture to the nick of person who have commented on. So The tables looks like:
Users .. ( big but.. we need just one collum)
Comments table:
Any ideas? I have solution but is ultra slow....
I wrote hardly something like this
PHP Code:
SELECT c.*,tu.profile_picture_ultra_small FROM comments AS c LEFT JOIN users AS tu ON c.nick = tu.nick WHERE status_id IN (3398,3342,3129,2895,2157,2072,2062,1995,1945,1915)