我正在使用此mysql查詢並對其進行排序,我已添加bool列is_main(是否來自主表)。結果是工作,但我得到重複,因爲is_main列..有沒有解決這個問題? 查詢:mysql UNION重複項
SELECT
b.dateTime,
a.id,
a.jobName,
a.is_main
FROM job_data a, data b
WHERE a.userEmail = b.userEmail AND a.userEmail = :email
UNION
SELECT
b.dateTime,
b.id,
b.jobName,
b.is_main
FROM job_data a, data b
WHERE a.userEmail = b.userEmail AND a.userEmail = :email
ORDER BY is_main DESC
的job_data表:
id | dateTime | jobName | is_main
1 | 00.00.00 | job1 | 0
2 | 00.00.00 | job2 | 0
3 | 00.00.00 | job3 | 0
數據表:
id | dateTime | jobName | is_main
1 | 00.00.00 | job1 | 1
2 | 00.00.00 | --- | 1
輸出是這樣的:
job1 //this is not okay, because of duplicate job1
job1
job2
job3
_____
--- //this is perfect, because I want empty cell to show on top
job1
job2
job3
什麼是重複的?我建議顯示一個輸出樣本。 – YakovL
@YakovL我編輯的問題,顯示輸出和表 – Atis