July 24, 2008 at 5:39 am
Hi there,
I am new on SQL. Ive been working on basic select statment. Now I just came up a complex query that ı dont understand. we can do a subguery in a FROM clause and where clause. what is the mean differences between them? Is the result same or not? How do they work?
If you have any idea please let me know. I am getting lost in all those.
thanks in advance
July 24, 2008 at 7:45 am
The answer to that really depends on the query in question. Here's an example where each results in the same data
SELECT a.*
FROM TableA a
WHERE a.ColA IN (SELECT ColA FROM TableB)
SELECT a.*
FROM TableA a
JOIN (SELECT ColA FROM TableB) b
ON a.ColA = b.ColA
SELECT a.*
FROM TableA a
JOIN TableB b
ON a.ColA = b.ColA
While the data is the same, the first query is probably going to be very slow when compared to the other two. Without more details, it's hard to say if your case is the same or not.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply