Click here to Skip to main content
15,921,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just came across with following query that is written by some senior guy. Now I have a doubt in that whether this way of writing query is correct and does it effects any performance..?.Please help me to understand the concepts.

(select * from table1) a
left outer join (select * from table2) b on b.column1=a.column1

What I have tried:

kindly help me.The query which I provided is just a example of real query.
Posted
Updated 2-Jan-18 23:13pm

Quote:
Now I have a doubt in that whether this way of writing query is correct and does it effects any performance..?
There's nothing better than documentation for that, see
Using Outer Joins[^]. Once you have established the correctness of the approach then you might investigate on performance. You maight find many, many, many resources available on the web.
 
Share this answer
 
Comments
Member 11337367 3-Jan-18 3:24am    
Thanks for your reply.I have good experience in sql.i know the syntax of joins.Here my doubt is the programmer used parenthesis for single table like
(select * from table1) a
left outer join (select * from table2) ..

instead of writing like this

select * from table1 a
join table2 b...
Maciej Los 3-Jan-18 5:14am    
5ed! Reading a documentation is always good idea.
The syntax should be like this:

select * from table1 a left outer join table2 b on a.column1=b.column1
 
Share this answer
 
Comments
Maciej Los 3-Jan-18 5:09am    
And the syntax - de facto - is as you mentioned. Brackets changes nothing.
Yes, above sql statement is absolutely correct. Carlo is right, you have to read a documentation. Main difference is:

MSDN wrote:
Inner joins return rows only when there is at least one row from both tables that matches the join condition. Inner joins eliminate the rows that do not match with a row from the other table. Outer joins, however, return all rows from at least one of the tables or views mentioned in the FROM clause, as long as those rows meet any WHERE or HAVING search conditions. All rows are retrieved from the left table referenced with a left outer join, and all rows from the right table referenced in a right outer join. All rows from both tables are returned in a full outer join.


For further details and "visualization", please see: Visual Representation of SQL Joins[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900