DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to use SQL self-join?

Execute the following SQL Server T-SQL script in Query Editor to demonstrate the use of self-join on the ProductVendor table to find products with multiple vendors:

USE AdventureWorks;

GO

SELECT DISTINCT

      ProductName=p.Name,

      ProductNumber,

      Vendor=v.Name

FROM Purchasing.ProductVendor pv1

-- This is a self-join

INNER JOIN Purchasing.ProductVendor pv2

      ON pv1.ProductID = pv2.ProductID

      AND pv1.VendorID != pv2.VendorID

INNER JOIN Production.Product p

      ON pv1.ProductID = p.ProductID

INNER JOIN Purchasing.Vendor v

      ON pv1.VendorID = v.VendorID

ORDER BY

      ProductName,

      Vendor

GO   

/*

ProductName       ProductNumber     Vendor

Chainring         CR-7833           Beaumont Bikes

Chainring         CR-7833           Bike Satellite Inc.

Chainring         CR-7833           Training Systems

Chainring Bolts   CB-2903           Beaumont Bikes

Chainring Bolts   CB-2903           Bike Satellite Inc.

Chainring Bolts   CB-2903           Training Systems

Chainring Nut     CN-6137           Beaumont Bikes

Chainring Nut     CN-6137           Bike Satellite Inc.

.....

*/

 

Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE