SQL - Queries Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

_______is the clause we use every time we want to query information from a database.

A

SELECT

SELECT column1, column2
FROM table_name;

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

_______renames a column or table.

A

AS

SELECT name AS ‘Titles’
FROM movies;

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

_______ return unique values.

A

DISTINCT

SELECT DISTINCT tools
FROM inventory;

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

_______is a popular command that lets you filter the results of the query based on conditions that you specify.

A

WHERE

SELECT *
FROM movies
WHERE imdb_rating > 8;

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

_______and _______are special operators.

A

LIKE, BETWEEN

SELECT *
FROM movies
WHERE name LIKE ‘A%’;

SELECT *
FROM movies
WHERE year BETWEEN 1990 AND 1999;

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

_______ and _______ combines multiple conditions.

A

AND, OR

SELECT *
FROM movies
WHERE year BETWEEN 1990 AND 1999
AND genre = ‘romance’;

SELECT *
FROM movies
WHERE year > 2014
OR genre = ‘action’;

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

_______ sorts the result.

A

ORDER BY

SELECT *
FROM movies
ORDER BY name;

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

_______ specifies the maximum number of rows that the query will return.

A

LIMIT

SELECT *
FROM movies
LIMIT 10;

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

_______ creates different outputs

A

CASE

SELECT name,
CASE
WHEN imdb_rating > 8 THEN ‘Fantastic’
WHEN imdb_rating > 6 THEN ‘Poorly Received’
ELSE ‘Avoid at All Costs’
END
FROM movies;

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

Find the error in this code:

SELECT name,
CASE
WHEN imdb_rating > 8 THEN ‘Oscar’
WHEN imdb_rating > 7 THEN ‘Good’
WHEN imdb_rating > 6 THEN ‘Fair’
FROM movies;

A

Missing END statement.

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

IS NULL condition returns true if the field has no value. T/F?

A

T

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

How would you query all the unique genres from the ‘books’ table?

A

SELECT DISTINCT genres
FROM books;

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

What is LIKE?

A

A special operator that can be used with the WHERE clause to search for a pattern.

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

What does the wildcard character % in the following SQL statement do?

SELECT *
FROM sports
WHERE name LIKE ‘%ball’;

A

It matches all sports that end with ‘ball’.

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

What is the correct syntax to query both the name and date columns from the database?

SELECT __________
FROM album;

A

name, date

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

What code would you add to this query to place the colors in reverse alphabetical order (Z to A) by name?

SELECT *
FROM colors
_________________;

A

ORDER BY name DESC

17
Q

What is ORDER BY?

A

A clause that sorts the result set alphabetically or numerically.

18
Q

What is LIMIT?

A

A clause that lets you specify the maximum number of rows the result set will have.

19
Q

Which of the following is NOT a comparison operator in SQL?

!=

> =

~

<

A

~

20
Q

Quiz: Queries
Which operator would you use to query values that meet all conditions in a WHERE clause?

A

AND

21
Q

What is the correct query to select only the cities with temperatures less than 35?

SELECT *
FROM cities;

SELECT *
FROM cities
WHERE temperature != 35;

SELECT *
FROM cities
WHERE temperature = 35;

SELECT *
FROM cities
WHERE temperature < 35;

A

SELECT *
FROM cities
WHERE temperature < 35;