Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding difference between to selects

Status
Not open for further replies.

room24

Programmer
Dec 28, 2003
83
JM
select supplier_id
from suppliers
MINUS
select supplier_id
from orders;

whats the equivalent of this query using sql server??
 
Give this a try ...

Code:
select
(select supplier_id 
from suppliers)
-
(select supplier_id 
from orders)
 
jby1,

That won't work. MINUS in ORACLE isn't equivlent to subtraction. This is similar to a UNION in reverse. It returns the Supplier_IDs from Suppliers table that are NOT IN the Orders table.

So, this might work....

Code:
SELECT Supplier_ID
FROM Supplier
WHERE Supplier_ID NOT IN (SELECT Supplier_ID
                          FROM Orders)

-SQLBill
 
Code:
select supplier_id 
from suppliers
Left join
from orders
on suppliers.supplier_id = orders.Supplier_id
where Orders.supplier_id is null

This version should be more efficient than using not in.

Questions about posting. See faq183-874
 
select supplier_id
from suppliers
Left join
from orders
on suppliers.supplier_id = orders.Supplier_id
where Orders.supplier_id is null

there is something wrong with the syntax in the code above
 
Oops, I was modifying your code and forgot to take out the from in front of orders.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top