Monday, November 1, 2010

SQL Exclusion Join

,
We know that SQL has a join syntax to query data within two tables. For example I have two tables and data like this :

Rose
type    |    price
-----------------------
Red     |      2
White   |      6


Lily
type           |    price
------------------------------
Bowl Shaped    |      5
Trumpet Shaped |      6


If we use a join, the tables must have condition to join them. But, how if we want to query data from one tables which doesn't exist in the other table? For example, I want to retrieve price of rose that not match in the lily? The answer is :
select * from rose a where a.price not in (select b.price from lily b) 

I hope this can help you for querying data. :D

0 comments to “SQL Exclusion Join”

Post a Comment