full join
|
|
SELECT column_name(s)
|
FROM table1
|
FULL OUTER JOIN table2
|
ON table1.column_name = table2.column_name
|
WHERE condition;
|
|
|
SELECT Customers.CustomerName, Orders.OrderID
|
FROM Customers
|
FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID
|
ORDER BY Customers.CustomerName;
|
 |
|
self join
|
|
SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City
|
FROM Customers A, Customers B
|
WHERE A.CustomerID <> B.CustomerID
|
AND A.City = B.City
|
ORDER BY A.City;
|
|
|
|
union
|
|
select a two tables, get the all elements which is common in
both tables and if repeat, write only one
|
|
SELECT City FROM Customers
|
UNION
|
SELECT City FROM Suppliers
|
ORDER BY City;
|
- Each SELECT statement within UNION must have the same number of columns
- The columns must also have similar data types
- The columns in each SELECT statement must also be in the same order
|
union all write duplicate values also
|
|
|
for example we have a names with 10 times repeat, we want to
know how many times it repeated
|
|
SELECT COUNT(CustomerID), Country
|
FROM Customers
|
GROUP BY Country;
|
|
I want to know on same address or same country how many body are
there
|
|
using group by we can know
|
|
|
descind order write
|
|
|
SELECT COUNT(CustomerID), Country
|
FROM Customers
|
GROUP BY Country
|
ORDER BY COUNT(CustomerID) DESC;
|
|
|
|
|
SELECT Shippers.ShipperName, COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
|
LEFT JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID
|
GROUP BY ShipperName;
|
|
ist it joins orders and shippers , to display it has
condion where both ids are matched, that
|
where both ids are matched order rows only we will show
combination and left element order only
|
|
we got all rows, from that rows it will show orders.orderid
and shippers.shippername
|
shippers.shippername is repeat how manytimes, that number
will show and shipper name will show
|
|
|
|
|
|
sql having
|
|
we shown how manytimes shipper repeats, if shipper repeates
greater than 5 times that willonly show
|
|
SELECT COUNT(CustomerID), Country
|
FROM Customers
|
GROUP BY Country
|
HAVING COUNT(CustomerID) > 5;
|
|
|
SELECT COUNT(CustomerID), Country
|
FROM Customers
|
GROUP BY Country
|
HAVING COUNT(CustomerID) > 5
|
ORDER BY COUNT(CustomerID) DESC;
|
|
|
|
|
where matches at that joins means combination got, how many
times repeats of last name writes andwrites if count>10 only
|
|
SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders
|
FROM (Orders
|
INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID)
|
GROUP BY LastName
|
HAVING COUNT(Orders.OrderID) > 10;
|
|
|
|
No comments:
Post a Comment