我有一個類似下面這個查詢的查詢。MySQL對ORDER做出例外?
SELECT name, id, note_date, note
FROM example
ORDER BY name, note_date
假設我有一個名爲「John Smith」的用戶。我希望查詢能夠按原樣工作,除非我希望John Smith的所有條目違反命令並出現在列表頂部。
我只是想知道是否有一個更簡單或更正確的方法來做到這一點,而不是一個JOIN(如下圖)。
此外,如果它很重要,「約翰史密斯」在任何給定的時間可能會或可能不會有條目。
謝謝!
像:
SELECT name, id, note_date, note
FROM example
WHERE name = "John Smith"
ORDER BY note_date
JOIN
SELECT name, id, note_date, note
FROM example
WHERE name != "John Smith"
ORDER BY name, note_date
爲什麼使用JOIN這裏?聯盟似乎更合適。 – Mikhail