SELECT *
FROM Customers;
SELECT CustomerName, City, Country
FROM Customers;
SELECT DISTINCT Country
FROM Customers;
SELECT *
FROM Customers
WHERE Country = "USA";
SELECT *
FROM Customers
Where Country = "USA" OR Country = "UK" OR Country = "Brazil";
SELECT *
FROM Customers
WHERE Country IN ("USA", "Mexico", "UK");
SELECT Country, City, CustomerName
FROM Customers
WHERE Country IN ("USA", "Mexico", "UK")
ORDER BY Country;
SELECT Country, City, CustomerName
FROM Customers
WHERE Country IN ("USA", "Mexico", "UK")
ORDER BY Country, City;
SELECT Country, City, CustomerName
FROM Customers
WHERE Country IN ("USA", "Mexico", "UK")
ORDER BY Country ASC, City DESC;
SELECT *
FROM Customers
Where Country = "USA" AND City = "Eugene";
SELECT *
FROM Products
WHERE Price >=10 AND Price <=20;
SELECT *
FROM Products
WHERE Price BETWEEN 10 AND 20;
SELECT *
FROM Employees
WHERE BirthDate BETWEEN "1950-01-01" AND "1959-12-31";
SELECT CustomerName
FROM Customers
WHERE CustomerName LIKE "_a%";
SELECT CustomerName, City, Country
FROM [Customers]
Where CustomerName Like "a%"
SELECT *
FROM [Employees]
where notes like "% BA%" Or notes like "% BSc%" or notes like "% Bts%"
SELECT *
FROM Products
where unit like "% bottle%" and price > 9;
SELECT *
FROM Customers
ORDER BY Country Desc;
SELECT Country, COUNT(Country)
FROM Customers
GROUP BY Country;
SELECT CategoryID, Count(CategoryID)
From Products
GROUP BY CategoryID;
SELECT CategoryID, Count(CategoryID) AS NoOfProducts
From Products
GROUP BY CategoryID;
SELECT CategoryID, Count(CategoryID) AS [No Of Products]
From Products
GROUP BY CategoryID;
SELECT CategoryID, Count(CategoryID) AS [No Of Products]
From Products
GROUP BY CategoryID
Having Count(CategoryID) >10;
SELECT country,count(country)
FROM [Customers]
group by country
having count(country)>6;
SELECT Country, Count(Country)
FROM Customers
GROUP BY Country
HAVING Count(Country) <=5
ORDER BY Country Desc;
SELECT ProductName, SupplierName
FROM Products, Suppliers
WHERE Suppliers.SupplierID = Products.SupplierID;
SELECT OrderID, OrderDate, LastName
FROM Orders, Employees
WHERE Employees.EmployeeID = Orders.EmployeeID;
SELECT ORDERID AS ID, CustomerName AS Customer, LastName AS Employee
FROM Orders AS O, Customers AS C, Employees AS E
WHERE C.CustomerID = O.CustomerID
AND E.EmployeeID = O.EmployeeID;
SELECT OD.OrderID, P.ProductName, OD.Quantity AS Qty, P.Price , OD.Quantity *
P.Price AS Amount
FROM OrderDetails AS OD, Products AS P
WHERE P.ProductID = OD.ProductID;
SELECT LastName AS Employee, Count(O.EmployeeID) AS [No. of orders taken]
FROM Orders AS O, Employees AS E
WHERE E.EmployeeID = O.EmployeeID
GROUP BY O.EmployeeID;
SELECT OD.OrderID AS [ORDER No.], C.CustomerName AS [Customer Name],
E.FirstName AS [Employee FN], Count(OD.OrderID) AS [No. of Prods on Order],
Sum(OD.Quantity * P.Price) AS [Order Amount]
FROM Customers AS C, Orders AS O, Employees AS E, OrderDetails AS OD, Products AS P
WHERE C.CustomerID = O.CustomerID
AND E.EmployeeID = O.EmployeeID
AND O.OrderID = OD.OrderID
AND P.ProductID = OD.ProductID
GROUP BY OD.OrderID;
UPDATE Products
SET Price = Price * 1.1
WHERE CategoryID = 1;
DELETE
FROM Products
WHERE CategoryID=1;
INSERT INTO Shippers
VALUES (4,"TCS","(021) 444-6667");
INSERT INTO Shippers(ShipperName,Phone)
VALUES ("TCS","(021) 444-6667");
INSERT INTO Customers(CustomerName, City, Country)
VALUES ("Askari","Karachi","Pakistan");
CREATE Database People;
CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
CREATE TABLE Persons (
ID int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);
CREATE TABLE Orders (
OrderID int NOT NULL PRIMARY KEY,
OrderNumber int NOT NULL,
PersonID int FOREIGN KEY REFERENCES Persons(PersonID)
);
DROP TABLE orders;
ALTER TABLE Persons
ADD Email varchar(255);
ALTER TABLE Customers
DROP COLUMN Email;