我有一個子查詢,看起來像這樣使用子查詢:在where子句
SELECT field1, (
SELECT date2
FROM table2
ORDER BY date2 DESC
) AS last_contacted
FROM table1
ORDER BY last_contacted DESC
但是,我得到記錄,其中last_contacted
爲NULL。我不希望這些結果中,所以我認爲WHERE last_contacted IS NOT NULL
但返回錯誤:
Unknown column 'last_contacted' in 'where clause'
所以,我怎麼能刪除那些從結果?
用'HAVING'替換'WHERE' – Mihai