Sunday, June 10, 2007

SQL EXISTS

Using a subquery to test for the existence of rows.
If it Exists Operators return a row, then the outer query proceeds. If not, the outer query does not execute or return any result or row.

Below is Example for SQL EXISTS

Company

Sales($)

Website

Sql Traniner2500http://www.sqltutorials.blogspot.com
BeautyCentury3000http://beautycentury.blogspot.com
TravelYourself2800http://travelyourself.blogspot.com
Table1

Sales

Website

2900http://www.sqltutorials.blogspot.com
3000http://beautycentury.blogspot.com
2800http://travelyourself.blogspot.com
Table2

SQL EXISTS Statement


SELECT * FROM TABLE1 WHERE EXISTS(SELECT * FROM TABLE2) Result

Company

Sales($)

Website

Sql Traniner2500http://www.sqltutorials.blogspot.com
BeautyCentury3000http://beautycentury.blogspot.com
TravelYourself2800http://travelyourself.blogspot.com



- We also can using the EXISTS in IF...ELSE Statement to checking the existence of a row or value.
- If IF...ELSE return true, it will return the result of Sql statement inside the BEGIN and END.

IF EXISTS(SELECT * FROM TABLE1 WHERE Company='TravelYourself')
BEGIN
SELECT * FROM TABLE1 WHERE Company='TravelYourself'
END

Result
TravelYourself2800http://travelyourself.blogspot.com

7 comments:

Ashley said...

WoW nice blog buddy!Actually WoW is my favorite appreciation keyword. I also like to play. Wow Gold. I was looking for info regarding that and saw your website. Its nice and very interesting.

Mind said...

buy Aion Kinah

Nice post

Mind said...

wow gold kaufen

Good post

Things to do in TN said...

I am having hard time understanding sql exists and not exists condition.Can you post some more examples.

Things to Do - Knoxville TN

GuildWars2Items said...

c9 online goldlife is not measured by the number of breaths we take, but by the moments that take our breath away buy c9 gold, ability may get you to the top, but it takes character to keep you there cheap c9 gold.

The past is gone and static. Nothing we can do will change it.scarlet blade gold, the future is before us and dynamic. Everything we do will affect it rs gold, You laugh at mescarlet blade gold for being different , but I laugh at you for being the same.

Sudhir DBAKings said...

Nice post very helpful

dbakings

Tamás Makkai said...

Hi. Yesterday I found an awesome itemshop where you can buy World of Warcraft gold, items, crafting materials. I got my order in a few minutes so I think they're the best wow itemshop there is. Their prices are quite cheap and I love how professional they are. Here's the link: http://www.mulefactory.com/wow/