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

HCL healthcare

 hcl health care f2f second round interview asked more uestions on microservice 1.apim manage all apis in one place 2.sql profiler in one fo...