chaiwei Posted January 11, 2010 Share Posted January 11, 2010 I have a table like this: job_id, resume_id, status, datestamp 3965 78826 accepted 2009-12-11 16:34:58 3965 79307 accepted 2009-12-17 11:04:36 3965 78826 can-rejected 2010-01-11 11:09:13 3965 56341 suitable 2009-12-03 11:25:58 3965 78826 suitable 2009-12-11 16:34:51 3965 79307 suitable 2009-12-17 11:04:33 I want it become like this job_id, resume_id, status, datestamp 3965 79307 accepted 2009-12-17 11:04:36 3965 78826 can-rejected 2010-01-11 11:09:13 3965 56341 suitable 2009-12-03 11:25:58 I can use subquery to do this: SELECT * FROM resume_application_status rjs, (SELECT max(datestamp) as datestamp FROM resume_application_status rjs GROUP BY job_id,resume_id ) rjs2 WHERE rjs.datestamp = rjs2.datestamp GROUP BY job_id,resume_id but this is subquery, are there any option to do this without using subquery? Because I can't create view using subquery Quote Link to comment https://forums.phpfreaks.com/topic/188009-mysql-query/ Share on other sites More sharing options...
Mchl Posted January 11, 2010 Share Posted January 11, 2010 As far as I can tell, you have to use subquery for that Quote Link to comment https://forums.phpfreaks.com/topic/188009-mysql-query/#findComment-992636 Share on other sites More sharing options...
fenway Posted January 16, 2010 Share Posted January 16, 2010 There are unorthodox ways to get that output with ORDER BY, HAVING and DISTINCT, but it's a hack. Quote Link to comment https://forums.phpfreaks.com/topic/188009-mysql-query/#findComment-995948 Share on other sites More sharing options...
chaiwei Posted January 18, 2010 Author Share Posted January 18, 2010 Hack? Interesting. Can you give me an example? I would love to learn more on sql. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/188009-mysql-query/#findComment-996950 Share on other sites More sharing options...
fenway Posted January 18, 2010 Share Posted January 18, 2010 Well, DISTINCT happens after the ORDER BY, so in principle, you can "discard" the others. Quote Link to comment https://forums.phpfreaks.com/topic/188009-mysql-query/#findComment-997488 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.