2. aggregate function Flashcards

1
Q

When we want to limit the results of a query based on values of the individual rows, use

A

WHERE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When we want to limit the results of a query based on an aggregate property, use

A

HAVING

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

HAVING statement always comes ___ GROUP BY, but ___ ORDER BY and LIMIT.

A

HAVING statement always comes after GROUP BY, but before ORDER BY and LIMIT.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does LEFT JOIN do?

A

A left join will keep all rows from the first table, regardless of whether there is a matching row in the second table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the three requirements for primary keys?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is primary key?

A

a column that uniquely identifies each row of that table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is foreign key?

A

When the primary key for one table appears in a different table, it is called a foreign key.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which one is often more descriptive? Primary key or foreign key?

A

Foreign key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is this important to identify primary key and foreign key?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly