Friday, 15 January 2010

SQL Server WHERE NOT EXISTS not working -



SQL Server WHERE NOT EXISTS not working -

i have 3 below statements,

selects order numbers dont exist select orders.ordernumber orders inner bring together invoicecontrol on orders.ordernumber = invoicecontrol.ordernumber not exists (select ordernumber orders invoicecontrol.ordernumber = orders.ordernumber) selects specific order number not exist select ordernumber orders ordernumber = 987654 selects specific order number in corresponding table not exist select ordernumber invoicecontrol ordernumber = 987654

these 3 queries work in other scenarios regarding other tables not one, have made obvious error anywhere? below query ran , outputs:

the thought behind locate ordernumbers not exist in invoicecontrol, based on ordernumbers in orders tabl, top query homecoming value 987654 value has not yet been included in invoicecontrol table new order without invoice

because inner join create correspondents between orders.ordernumber = invoicecontrol.ordernumber.

after result set built, filter out based on status in where.

where not exists (select ordernumber orders invoicecontrol.ordernumber = orders.ordernumber)

hypothetically, if you'd have 987654 in orders table , you'd have correspondent in invoicecontrol table, next query, without where clause

select orders.ordernumber orders inner bring together invoicecontrol on orders.ordernumber = invoicecontrol.ordernumber

would return:

ordernumber 987654

then, applying where not exists (select ordernumber orders invoicecontrol.ordernumber = orders.ordernumber) condition, you'd looking records not have correspondent (but have possible correspondents between 2 tables, based on inner join).

thus, result be:

ordernumber

sql sql-server sql-server-2012

No comments:

Post a Comment