我正在嘗試從數據庫中返回所有工程師。除此之外,還有其他一些用戶信息。但我希望交流表加入最近的行,然後通過聯繫人名稱排序主要結果。SQL - 訂購左連接和主要結果
任何人都可以向正確的方向挑撥我嗎?
SELECT
mb.type, mb.contactname, mb.id, mb.inv_addressline2, mb.inv_addressline3, mb.signup_date,
fb.engineer_id, fb.job_id, fb.neg_or_pos, fb.rating, fb.author_id,
ac.engineer_id, ac.timestamp, ac.author_id,
jb.job_id, SUBSTRING(jb.job_description, 0, 200) AS `short_description`, jb.timestamp
FROM " . MEMBERS_TABLE . " AS mb
LEFT JOIN " . ACCEPTED . " AS ac ON mb.id = ac.engineer_id
LEFT JOIN " . FEEDBACK . " AS fb ON ac.job_id = fb.job_id
LEFT JOIN " . JOBS . " AS jb ON fb.job_id = jb.job_id
WHERE mb.type = 2
GROUP BY mb.contactname
ORDER BY ac.timestamp DESC
你是怎麼做的?歡呼 –