Posts

Showing posts from July, 2012

SQL JOIN's revisited.

Yesterday I was asked what's the difference between UNION and UNION ALL , it made me think, I've been writing Stored Procedures for SQL Server for quite some time now. But almost always forget what what the difference between the two. It's time to reinforce it by writing it down through this blog. UNION  is used to combine result-sets of two or more SELECT statements,  the difference is really simple in UNION it only joins distinct values, meaning if there are duplicates it wont show it from the result-set, that's where ALL keyword is used when you want to include the duplicates in return. Union Syntax: SELECT ProductId FROM Products UNION SELECT  ProductId FROM Orders This will return unique  ProductId from Products and Orders Table combined and will ignore duplicates. Up Next differences between INNER JOIN, OUTER JOIN , LEFT and RIGHT JOIN and let's not forget CROSS JOIN CROSS JOIN Using cross join multiplies your rows from the first table to t...