MSSQL Advanced Join Statements
Advanced Join Statements in MS SQL Management Studio.
There are several different Join types in here I will discuss them:
Cross Join Statement
Full Join Statement
Joining tables is one of the most useful operations we have. Large data should be divided to several tables (see Normalization Rules) for maximum flexibility and minimum resources usage.
Be careful when using the Cross Join. it might cause more damage than good.
Example:
SELECT TOP 100 P.ProductID,
P.Name,
P.ListPrice,
P.Size,
SOD.UnitPrice,
SOD.UnitPriceDiscount,
SOD.LineTotal
FROM Sales.SalesOrderDetail SOD
CROSS JOIN Production.Product P
WHERE SOD.UnitPrice > 3500
ORDER BY SOD.UnitPrice DESC
Example:
SELECT C.ContactID,
C.FirstName,
C.LastName,
SP.SalesPersonID,
SP.Bonus,
ST.TerritoryID,
ST.Name
FROM Person.Contact C
INNER JOIN Sales.SalesPerson SP
ON C.ContactID = SP.SalesPersonID
FULL OUTER JOIN Sales.SalesTerritory ST
ON ST.TerritoryID = SP.TerritoryID
ORDER BY ST.TerritoryID, C.LastName
Good luck,
Elad Shalom,
CTO at ITweetLive.com
There are several different Join types in here I will discuss them:
Cross Join Statement
Full Join Statement
Joining tables is one of the most useful operations we have. Large data should be divided to several tables (see Normalization Rules) for maximum flexibility and minimum resources usage.
Cross Join Statement:
In the Cross Join statement, based on the two tables within the Join, a Cartesian product is created if a 'Where' statement filter the rows. The size of the Cartesian product is based on multyplying the number of rows from the left table by the number of rows from the right one.Be careful when using the Cross Join. it might cause more damage than good.
Example:
SELECT TOP 100 P.ProductID,
P.Name,
P.ListPrice,
P.Size,
SOD.UnitPrice,
SOD.UnitPriceDiscount,
SOD.LineTotal
FROM Sales.SalesOrderDetail SOD
CROSS JOIN Production.Product P
WHERE SOD.UnitPrice > 3500
ORDER BY SOD.UnitPrice DESC
Full Outer Join Statement:
As you remember, the Left Join and Right Join statements where basically the same Select with different Join statements. In this example, the result is the same as the Left Join, with mile changes.Example:
SELECT C.ContactID,
C.FirstName,
C.LastName,
SP.SalesPersonID,
SP.Bonus,
ST.TerritoryID,
ST.Name
FROM Person.Contact C
INNER JOIN Sales.SalesPerson SP
ON C.ContactID = SP.SalesPersonID
FULL OUTER JOIN Sales.SalesTerritory ST
ON ST.TerritoryID = SP.TerritoryID
ORDER BY ST.TerritoryID, C.LastName
Good luck,
Elad Shalom,
CTO at ITweetLive.com
birkin bag, north face outlet, hogan, nike air max, new balance shoes, louis vuitton, timberland, hollister, nfl jerseys, air jordan, louis vuitton, abercrombie and fitch, longchamp, nike free, lancel, lululemon, supra shoes, oakley pas cher, rolex watches, converse shoes, montre pas cher, louis vuitton, nike air max, michael kors, mulberry, nike free, air max, ralph lauren, burberry, air max, ralph lauren, hermes, vans, beats by dre, wedding dresses, louboutin, yoga pants, ray ban pas cher, reebok outlet, karen millen
ReplyDeletenike free, louis vuitton outlet online, chanel handbags, oakley sunglasses, burberry outlet online, air max, tiffany and co, ray ban, prada outlet, ray ban sunglasses, burberry outlet online, louboutin, longchamp outlet, louboutin, coach outlet store, polo ralph lauren outlet, oakley sunglasses, jordan shoes, oakley sunglasses, coach factory outlet, coach outlet, nike shoes, michael kors outlet, gucci outlet, coach purses, coach factory, tory burch outlet, prada handbags, oakley sunglasses, toms shoes, louis vuitton handbags, true religion jeans, true religion outlet, kate spade outlet, ray ban sunglasses, true religion, polo ralph lauren, nike air max, oakley sunglasses, michael kors outlet
ReplyDeleteadidas neo
ReplyDeleteyeezy boost 350 v2
adidas superstar
polo lacoste
fitflops
yeezy boost 350 v2
adidas ultra boost
http://www.kobeshoes.uk
salomon speedcross
chrome hearts online
yeezy boost 350 v2
ReplyDeletecoach outlet online
nike roshe flyknit
toms outlet online
coach factory online
ed hardy jeans
ralph lauren outlet
polo ralph lauren
burberry handbags
ralph lauren outlet
2017.3.15chenlixiang
Thank you for sharing an interesting and very useful article. And let me share an article about health here I believe this is useful. Thank you :)
ReplyDeleteObat Berengan/Sariawan/Luka di Sudut Bibir
Obat Bruntusan Herbal
Masker Wajah untuk Kulit Berminyak dan Berjerawat