2. aggregate function Flashcards
When we want to limit the results of a query based on values of the individual rows, use
WHERE
When we want to limit the results of a query based on an aggregate property, use
HAVING
HAVING statement always comes ___ GROUP BY, but ___ ORDER BY and LIMIT.
HAVING statement always comes after GROUP BY, but before ORDER BY and LIMIT.
What does LEFT JOIN do?
A left join will keep all rows from the first table, regardless of whether there is a matching row in the second table.
What are the three requirements for primary keys?
- None of the values can be NULL
- Each value must be unique (i.e., you can’t have two customers with the same customer_id in the customers table)
- A table can not have more than one primary key column
What is primary key?
a column that uniquely identifies each row of that table
what is foreign key?
When the primary key for one table appears in a different table, it is called a foreign key.
Which one is often more descriptive? Primary key or foreign key?
Foreign key
Why is this important to identify primary key and foreign key?
The most common types of joins will be joining a foreign key from one table with the primary key from another table. For instance, when we join orders and customers, we join on customer_id, which is a foreign key in orders and the primary key in customers.