Friday, 30 September 2022

sql remove not existing ids in table one

How to Delete Rows That do not Exist in Another Table


 select a.orderid from web.orderHeader a

 WHERE web.orderHeader.orderid NOT IN (SELECT f.orderid 

                        FROM web.orderdetail f)

Using NOT IN:

DELETE FROM orderHeader
 WHERE orderid NOT IN (SELECT f.orderid 
                        FROM orderdetail f)

Using NOT EXISTS:

DELETE FROM orderHeader
 WHERE NOT EXISTS(SELECT NULL
                    FROM orderdetail f
WHERE f.id = fileid)

No comments:

Post a Comment

API run block issue run api from cmd

  ✅ Debug Checklist – “Access is Denied” (.NET / Visual Studio) 🔹 Identify Problem ☐ Error: Unable to start program (.exe) – Access is deni...