我有兩個表,例如:SQL - 檢查並更新新表的行數?
Table firstfile Table secondfile
=============== ================
Emplid | Color Emplid | Color |status
---------------------- -------------|---------|------
123 | red 123 | red |
456 | green 456 | Green |
789 | black 000 | red |
789 | black |
999 | white |
表firstfile是我的源表和secondfile是目標表。現在我需要一個查詢來查找表secondfile中的所有不同(額外)行。所以我需要一個查詢,找到我以下內容:
Table secondfile
================
Emplid | Color | Status
-------------------------------
123 | red |
456 | Green |
000 | red | added
789 | black |
999 | white | added
這樣的查詢的好方法是什麼?
我試過,但它不工作
UPDATE secondfile
INNER JOIN firstfile
ON secondfile.Emplid = firstfile.Emplid
SET status = (CASE WHEN secondfile.Emplid != firstfile.Emplid THEN 'Added' END)
您無法同時更新和加入。 – Setop
誰說的?嘗試我的代碼 – Susang