What is SQL?
Structured Query Language is used to store, retrieve, filter, and analyze data in relational databases.
What is PostgreSQL?
An open-source relational database system that uses SQL.
What is a database?
A collection of tables that store related data.
What is a table?
A structured set of rows and columns.
What is a row?
one record
What is a column?
one attribute of the data
What is the basic SQL query order?
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
LIMIT
What does SELECT do?
chooses which columns to return
SELECT name, age FROM users;
What does FROM do?
specifies the table to query
What does SELECT * do?
returns all columns
What does WHERE do?
filters rows based on conditions
WHERE age > 21
What are the comparison operators?
=, !=, <, >, <=, >=
What are the logical operators?
AND, OR, NOT
What does BETWEEN do?
WHERE age BETWEEN 18 AND 30
What does IN do?
specifies constraints
WHERE country IN (‘US’, ‘CA’)
What does LIKE do?
contains portions of strings to match
WHERE email LIKE ‘%@gmail.com’
What is a NULL?
missing or unknown value
Why can’t we use = NULL?
NULL is not equal to anything, even NULL
What is the correct way to check NULL?
WHERE column IS NULL
WHERE column IS NOT NULL
What is COALESCE?
replace NULL with a default value
ex: COALESCE(score, 0)
What does ORDER BY do?
sorts results
ex: ORDER BY created_at DESC
What is ASC vs DESC?
ascending vs descending
What does LIMIT do?
limits the number of rows returned
ex: LIMIT 10
What is aggregation?
combining multiple rows into a single value