Mr Chris Posted June 2, 2010 Share Posted June 2, 2010 Hello All, I have a query which looks in two tables for data and performs a join and works great: SELECT DISTINCT dc.order_id, dc.id, dc.campaign_name, dc.campaign_start_date, dc.campaign_end_date, dc.salesperson, dc.ad_type, dws.order_id, dws.impressions, dws.clicks FROM cart_campaigns AS dc INNER JOIN cart_weekly_stats AS dws ON dc.order_id = dws.order_id AND dc.campaign_start_date = (SELECT MAX(campaign_start_date) FROM dart_weekly_stats WHERE order_id = dc.order_id) WHERE dc.salesperson = '10' ORDER BY dc.order_id DESC However, I just have one problem I simply want the result to output the LATEST row for each order_id, when as you can see in the below it outputs all the results, so I just want the highlighted latest ones returned that are both different order id's (the latest ones for that particular order_id)? Can anyone help as this has been winding me up all morning! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/203616-help-with-a-join-getting-only-the-latest-results-in-the-table/ Share on other sites More sharing options...
luca200 Posted June 3, 2010 Share Posted June 3, 2010 Latest? How do you decide which is the latest? There is no data that can show it Quote Link to comment https://forums.phpfreaks.com/topic/203616-help-with-a-join-getting-only-the-latest-results-in-the-table/#findComment-1067074 Share on other sites More sharing options...
PFMaBiSmAd Posted June 3, 2010 Share Posted June 3, 2010 http://dev.mysql.com/doc/refman/5.1/en/example-maximum-column-group-row.html Quote Link to comment https://forums.phpfreaks.com/topic/203616-help-with-a-join-getting-only-the-latest-results-in-the-table/#findComment-1067131 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.