1
我需要一個SQL查詢,用於從兩個表中選擇多個條件。從條件中選擇
table1
order_row | timestamp |
-----------------------
0001 |2016-11-04 |
0002 |2016-11-04 |
0003 |2016-11-04 |
0004 |2016-11-03 |
0006 |2016-11-03 |
table2
order_row | timestamp |
-----------------------
0001 |2016-11-05 |
0002 |2016-11-04 |
0003 |2016-11-04 |
0004 |2016-11-04 |
0005 |2016-11-04 |
0006 |2016-11-02 |
我想所有的行,使我得到table2
至極所有order_row
行不是從table2
其時間戳是table2
比table1
新出現在table1
和order_row
行。而檢測開關只能從table 2
至極行timestamp
較新,2016年11月3日 結果必然是:
order_row |
----------
0001 | because timestamp is newer in table2
0004 | because timestamp is newer in table2
0005 | because it's not present in table1
感謝您的快速響應。我還有一個問題。例如,我如何在查詢檢查表2中時間戳比2016-11-03更新的行中添加條件。 – Kalle
@Kalle您可以添加謂詞't2.timestamp>'2016-11-03'',並將其與't2.timestamp> t1.timestamp'結合使用,以防您希望更新的記錄*和*記錄超過特定日期。 –
現在所有的作品。謝謝。我必須學習更多的:) – Kalle