Skip to content

Instantly share code, notes, and snippets.

View bartubozkurt's full-sized avatar
🎯
Focusing

Bartu Bozkurt bartubozkurt

🎯
Focusing
View GitHub Profile
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
@bartubozkurt
bartubozkurt / insert_into2.sql
Created June 12, 2021 21:26
If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table.
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
@bartubozkurt
bartubozkurt / insert_into.sql
Created June 12, 2021 21:24
INSERT statement is used to insert a single record or multiple records into a table in SQL Server.
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
@bartubozkurt
bartubozkurt / natural_join.sql
Created June 11, 2021 19:56
join tables by all columns with the same name.
SELECT city.name, country.name
FROM city
NATURAL JOIN country;
@bartubozkurt
bartubozkurt / full_outter_join.sql
Created June 11, 2021 19:53
(or explicitly FULL OUTER JOIN) returns all rows from both tables - if there's no matching row in the second table, NULLs are returned.
SELECT city.name, country.name
FROM city
FULL JOIN country
ON city.country_id = country.id;
@bartubozkurt
bartubozkurt / right_join.sql
Created June 11, 2021 19:47
It is used to merge all rows from the second selected table and the matching rows from the first selected table. Returns null if there is a value in the second table that does not match the first table
SELECT city.name, country.name
FROM city
RIGHT JOIN country
ON city.country_id = city.id;
@bartubozkurt
bartubozkurt / left_join.sql
Created June 11, 2021 19:44
It is used to combine all rows in the first selected table and matching rows in the second selected table. If the values in the first table do not match the values in the second table, it gets null.
SELECT city.name, country.name
FROM city
LEFT JOIN country
ON city.country_id = country.id;
@bartubozkurt
bartubozkurt / inner_join.sql
Created June 11, 2021 19:38
The INNER JOIN statement is used to join tables with a common value.
SELECT city.name, country.name
FROM city
INNER JOIN country
ON city.country_id = country.id;
@bartubozkurt
bartubozkurt / except.sql
Created June 11, 2021 19:28
Displays DE cyclists unless they are also DE skaters at the same time
SELECT name
FROM cycling
WHERE country = 'DE'
EXCEPT
SELECT name
FROM skating
WHERE country = 'DE';
@bartubozkurt
bartubozkurt / intersect.sql
Created June 11, 2021 19:23
Displays DE cyclists who are also DE skaters at the same time
SELECT name
FROM cycling
WHERE country = 'DE'
INTERSECT
SELECT name
FROM skating
WHERE country = 'DE'