獲得從如下表最大的結果(日期)Mysql的加入獲得最大的日期相關的表項
導致表
id name
1 name1
2 name2
3 name3
遵循
id lead_id msg date
1 1 msg1 20-01-2015
2 1 msg2 22-01-2015
3 1 msg3 24-01-2015
4 2 msg22 21-01-2015
5 3 msg31 22-01-2015
6 3 msg32 24-01-2015
什麼我真的很期待看到數據如
lead_id name msg date
1 name1 msg3 24-01-2015
2 name2 msg22 21-01-2015
3 name3 msg32 24-01-2015
$todayStart = mktime(0, 0, 0, $mon, $day-1, $year);
SELECT * FROM (`follow`) LEFT JOIN `leads` ON `leads`.`id` = `lead_id` WHERE `date` <= $todayStart GROUP BY `leads`.`id` ORDER BY `follow`.`date` DESC
目前即時通訊做加盟兩種表的表和使用的foreach發現最大日
foreach($resultarray as $p){
SELECT `id` FROM (`follow`) WHERE `lead_id` = ".$p->id." AND `date` > ".$p->date." ORDER BY `updated_on` DESC"
}
任何幫助在單個查詢優化該