mysqlでグループごとの最新の日付の一覧を取得したい場合
SELECT * FROM
tb_m_contact1 as con1
left JOIN tb_m_anken ON con1.contact1_a_id = tb_m_anken.anken_id
left JOIN pl_su1 ON con1.contact1_c_id = pl_su1.su1_id
WHERE `contact1_update1`=(SELECT MAX(`contact1_update1`)
FROM tb_m_contact1 WHERE contact1_remarks3=con1.contact1_remarks3)
and (contact1_u_id = '181961' or contact1_c_id = '181961' or contact1_remarks2 = '181961' or contact1_flg_id='181961')
https://www.it-swarm-ja.tech/ja/mysql/%E6%9C%80%E5%A4%A7%E6%97%A5%E4%BB%98%E3%82%92%E6%8C%81%E3%81%A4group-by/1040826047/
その2
SELECT
staff_aid,
staff_id,
CONVERT( AES_DECRYPT( UNHEX(staff_name1),'$this->vkey1') USING utf8 ) as staff_name1,
chat1.chat1_u_id as chat1_u_id,
CONVERT( AES_DECRYPT( UNHEX(chat1.chat1_u_name),'$this->vkey1') USING utf8 ) as chat1_u_name,
chat1.chat1_datetime,
CONVERT( AES_DECRYPT( UNHEX(chat1.chat1_su_name),'$this->vkey1') USING utf8 ) as chat1_su_name,
CONVERT( AES_DECRYPT( UNHEX(chat1.chat1_message),'$this->vkey1') USING utf8 ) as chat1_message
FROM
co_staff
LEFT JOIN pl_su_chat1 as aa ON
co_staff.staff_id = aa.chat1_u_id
LEFT JOIN pl_su_chat1 AS chat1 ON
co_staff.staff_id = chat1.chat1_u_id
LEFT JOIN
pl_su_chat1 AS chat2 ON (chat1.chat1_u_id = chat2.chat1_u_id AND chat1.chat1_datetime < chat2.chat1_datetime)
WHERE
chat2.chat1_datetime IS NULL
コメント