I have one show table which have 25 lakh records in it. Columns in show tables is id, showid, artist_id, cityid, created.
If same show is happening for a period of 4 days. Then in system data will be like :
id, showid, artist_id, cityid, created for each show, showid will remain same.
1 245 1 3 2011-12-30 15:00:00
2 245 1 3 2011-12-30 13:00:00
3 245 1 3 2011-12-30 19:00:00
SELECT UT.user_id,UT.type_id, UT.type ,UT.track_time,
(SELECT showid FROM shows WHERE FIND_IN_SET(UT.type_id,artist_id) ORDER BY created DESC LIMIT 1) as mainshowid,
(SELECT cityid FROM shows WHERE FIND_IN_SET(UT.type_id,artist_id) ORDER BY created DESC LIMIT 1) as maincityid
FROM user_details as UT WHERE UT.type='artist' ORDER BY UT.track_time desc limit 20;
Query is giving the desire output But how i can get multiple columns in single SUB query or by any other way.