Skip to content

Instantly share code, notes, and snippets.

View bartubozkurt's full-sized avatar
🎯
Focusing

Bartu Bozkurt bartubozkurt

🎯
Focusing
View GitHub Profile
SELECT * FROM Customers
ORDER BY Country
@bartubozkurt
bartubozkurt / having_intermediate.sql
Created June 13, 2021 09:36
lists the employees that have registered more than 10 orders
SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders
From (Orders
INNER JOIN Employees ON Orders.EmployeesID = Employees.EmployeeID)
GROUP BY LastName
HAVİNG COUNT(Orders.OrdersID) > 10;
@bartubozkurt
bartubozkurt / having_ex.sql
Created June 13, 2021 09:30
lists the number of customers in each country, sorted high to low (Only include countries with more than 5 customers)
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5
ORDER BY COUNT(CustomerID) DESC;
@bartubozkurt
bartubozkurt / having.sql
Created June 13, 2021 09:26
lists the number of customers in each country. Only include countries with more than 5 customers
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5 ;
@bartubozkurt
bartubozkurt / join_three_tables.sql
Created June 13, 2021 08:53
JOIN Three Tables Selects all orders with customer and shipper information:
SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName
FROM ((Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID)
INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID);
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
@bartubozkurt
bartubozkurt / update_warning.sql
Created June 13, 2021 08:36
Be careful when updating records. If you omit the WHERE clause, ALL records will be updated!
UPDATE Customers
SET ContactName = 'Sanchez';
@bartubozkurt
bartubozkurt / update_multiple.sql
Created June 13, 2021 08:34
UPDATE multiple records in database
UPDATE Customers
SET CustomerName = 'Bartu',
CustomerID = 91
WHERE Country= 'Poland';
@bartubozkurt
bartubozkurt / update_3.sql
Created June 13, 2021 08:31
update table
UPDATE Customers
SET ContactName = 'Karl John', City= 'İZMİR'
WHERE CustomerID = 89;
@bartubozkurt
bartubozkurt / update_2.sql
Created June 13, 2021 08:23
UPDATE statement when updating one table with data from another table in SQL Server
UPDATE table1
SET column1 = (SELECT expression1
FROM table2
WHERE conditions)
[WHERE conditions];