mysql - Return Only Last Row LEFT JOIN -


select distinct msg.userid, msg.messages, user.fullname, prof.path messages msg left join users user on msg.userid = md5( user.userid ) left join profile prof on msg.userid = prof.userid order msg.date asc limit 0 , 30 

the above code working problem result has duplicate values:

userid | messages | fullname | path 985434 | hello... | foo bar  | /path/to/hello.jpg 985434 | hello... | foo bar  | /path/to/new.jpg 

the problem path. how limit result of path recent? or 1 per fullname?...it's killing me thank understanding.

what want select users messages. want select 1 path per message. here example on how this:

select msg.userid, msg.messages, users.fullname,    (select max(path) profile profile.userid = msg.userid) maxpath messages msg left join users on msg.userid = md5( users.userid ) order msg.date asc; 

you can use group_concat instead of max, list of paths. sub select can more complex, looking last date instance (provided there date information in table).

why left outer join users messages way? there messages without associated users?


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -