我想實現一個內連接來比較兩個表中的值,但是沒有出於某種原因,並在查詢返回零列。內連接有兩個選擇的sql
我有兩個表的安全性和security_his並試圖加入他們列SECURITY_ID和INVESTMENT_OBJECTIVE。查詢如下
SELECT *
FROM SECURITY origin
INNER JOIN (
SELECT *
FROM SECURITY_HIS t2
WHERE DATED = (
SELECT MAX(DATED)
FROM SECURITY_HIS t1
WHERE t1.SECURITY_ID = t2.SECURITY_ID
)
) history ON origin.SECURITY_ID = history.SECURITY_ID
AND origin.INVESTMENT_OBJECTIVE = history.INVESTMENT_OBJECTIVE;
應儘量將包括對SQL問題'SqlServer','MySql' RDBMS的標籤?某些功能不適用於所有數據庫。 –
查詢看起來不錯,可能你沒有匹配的數據。檢查內部選擇的結果SELECT * FROM SECURITY_HIS t2 WHERE DATED =(' –
它是sqlServer和我有匹配的數據!應該是有問題的查詢 – user1200279