w3d1 Flashcards

1
Q

What is the syntax to check if an element is within a collection (in a WHERE clause)?

A

name IN (‘Denmark’, ‘Finland’, ‘Norway’, ‘Sweden’)

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

How can we retrieve a country that starts with the letter ‘G’

A

name LIKE ‘G%’;

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

Explain regex syntax for finding words that contain letters.

A

Use ‘LIKE’, then put a ‘%’ at the end of the string you are searching for.

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

In which years was the Physics prize awarded, but no Chemistry prize?

A
SELECT DISTINCT
      yr
    FROM
      nobels
    WHERE
      (subject = 'Physics' AND yr NOT IN (
        SELECT
          yr
        FROM
          nobels
        WHERE
          subject = 'Chemistry'
      ))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

T/F: values from an inner SELECT are inaccessible from an outer SELECT.

A

F; they are.

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

What is the order of evaluation in the SELECT-FROM-WHERE triad?

A

FROM is evaluated first, then WHERE, then SELECT.

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

Find each country that belongs to a continent where all populations are
less than 25,000,000. Show name, continent and population.

A
SELECT
      c1.name, c1.continent, c1.population
    FROM
      countries c1
    WHERE
      c1.continent NOT IN (
        SELECT
          c2.continent
        FROM
          countries c2
        WHERE
          c2.population >= 25000000
      );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do we get rid of repetition in SELECT clauses?

A

Use SELECT DISTINCT

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

What is up with the GROUP BY clause?

A

Tells how to combine elements:

SELECT
      continent, COUNT(*)
    FROM
      countries
    WHERE
      population >= 10000000
    GROUP BY
      continent;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain JOIN

A

You JOIN tables ON a value = another (logically correlated) value. The resulting table now has access to EVERYTHING from the previous tables.

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

What does the COALESCE keyword do?

A

Retrieves the first value from a list of values that is not NULL.

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

Explain the CASE-WHEN-ELSE clauses. Where are they used?

A

They are used within a SELECT clause, and follow the following syntactical guidelines:

SELECT
      teachers.name,
      CASE
        WHEN teachers.dept_id IN (1, 2) THEN 'Sci'
        ELSE 'Art'
      END AS dept_name
    FROM
      teachers;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does an unqualified JOIN represent?

A

INNER JOIN

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