我的消息收件箱概念電子郵件表是表中的主表。我想獲取特定電子郵件發送的最後一條消息。爲VARCHAR列選擇最大值 - MySQL
tbl_msg:
id
email
msg
示例數據:
Id email msg
1 [email protected] This is test
2 [email protected] All is well
3 [email protected] This is test2
我想每封電子郵件和味精最後出場的
Id email msg
2 [email protected] All is well
3 [email protected] This is test2
我的嘗試:
SELECT cnote.`id`,cnote.`email`,cnote.`msg` FROM `tbl_msg` cnote inner join (select distinct email,id from client_com group by email) as note
on cnote.id=note.id
指導我,如果我錯了
你可能會被這個得太多。爲什麼不只是last_insert_id? –
true ...只是獲取最後插入的記錄 –
爲每個電子郵件獲取last_inserted_id? –