MSSQL Joins

Here are some Example of SQL Joins


--The basic JOIN statement
-- JOIN:
SELECT Customer.CustomerID, TransID, TransAmt
FROM Customer JOIN Transaction
ON Customer.CustomerID = Transaction.CustomerID;


-- similar:
SELECT Customer.CustomerID, TransID, TransAmt
FROM Customer, Transaction;
where Customer.CustomerID = Transaction.CustomerID;

-- INNER JOIN
SELECT CustomerName, TransDate
FROM Customer INNER JOIN Transaction
ON Customer.CustomerID = Transaction.CustomerID;

-- LEFT OUTER JOIN
SELECT CustomerName, TransDate, TransAmt
FROM Customer LEFT OUTER JOIN Transaction
ON Customer.CustomerID = Transaction.CustomerID;

Advertisements