SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How SQL works Internally?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

grandhi
Starting Member

31 Posts

Posted - 05/15/2013 :  02:00:34  Show Profile  Reply with Quote
Hi All,

I want to write Intersect query with 3 different tables,for that purpose I wrote the following code.

select DataElement2 from test intersect select DataElement2 from test2 intersect select DataElement2 from test3


it's working fine,But I have a doubt about,is it right what I mention in below.

In my point of view the entire above query consider as a single query.Once we send the query to SQL,I think SQL understood as Three queries.

Is it right,What I am Thinking.like this I want to know If we use Joins between different tables.How SQl will understood.

I hope,you understand my question.

Fell Free,If you want to edit my question.

Thank you.


Edited by - grandhi on 05/15/2013 02:03:42

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 05/15/2013 :  02:09:42  Show Profile  Reply with Quote
The query engine will break it down into individual queries, fetch result for each and then apply intersect operator over them to give you the common values present.
In comparison, in a join the query engine fetches all the records from involved tables based on join condition and give you merged result

To get exact sequence you can run the query with "display actual execution plan" option on on SSMS and it will give you graphical representataion of actual query plan used in query.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000