Skip to content

Instantly share code, notes, and snippets.

View bartubozkurt's full-sized avatar
🎯
Focusing

Bartu Bozkurt bartubozkurt

🎯
Focusing
View GitHub Profile
@bartubozkurt
bartubozkurt / fetch_allcolumns.sql
Created June 11, 2021 17:18
Fetch all columns from the country table
SELECT * FROM country;
SELECT id, name FROM city;
@bartubozkurt
bartubozkurt / name_sorted_rating_asc.sql
Created June 11, 2021 17:21
Fetch city names sorted by the rating column in the default Ascending order:
SELECT name FROM city ORDER BY rating ASC;
SELECT names FROM city ORDER BY rating DESC;
@bartubozkurt
bartubozkurt / as_columns.sql
Created June 11, 2021 17:27
With the AS expression, we can temporarily give short names to long and difficult to use table or field names
SELECT name AS city_name FROM city;
@bartubozkurt
bartubozkurt / as_table.sql
Created June 11, 2021 17:29
With the AS expression, we can temporarily give short names to long and difficult to use table or field names
SELECT co.name, ci.name
FROM city AS ci
JOIN country AS co
ON ci.country_id = co.id;
@bartubozkurt
bartubozkurt / operators.sql
Created June 11, 2021 17:35
Fetch names of cities that have a rating above 3
SELECT name FROM city WHERE rating > 3;
@bartubozkurt
bartubozkurt / sql_!.sql
Created June 11, 2021 17:38
Fetch names of cities that are neither Berlin nor Madrid
SELECT name
FROM city
WHERE name != 'Berlin' AND name != 'Madrid';
@bartubozkurt
bartubozkurt / text_operators.sql
Created June 11, 2021 17:41
Fetch names of cities that start with a 'P' or end with an 's'
SELECT name
FROM city
WHERE name LIKE 'P%' OR name LIKE '%s';
@bartubozkurt
bartubozkurt / text_operators_2.sql
Created June 11, 2021 17:46
Fetch names of cities that start with any letter followed by 'ublin' (like Dublin in Ireland or Lublin in Poland)
SELECT name
FROM city
WHERE name LIKE '_ublin';