1.3.2D SQL Flashcards

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

Write a SQL command to select all the columns from the “celebs” table.

A

SELECT * FROM celebs;

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

What type of programming language is SQL?

A

Declarative.

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

What type of programming language is SQL?

A

Declarative

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

Write a SQL command to select all the columns from the “celebs” table.

A

SELECT * FROM celebs;

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

Write a SQL command to insert the following data into the table “celebs”

Data:
1
Justin Bieber
21

Columns:
ID
Name
Age

A

INSERT INTO celebs ([ID], [Name], [Age]) VALUES (1, ‘Justin Bieber’, 21);

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

Write a SQL command to update the following data in the table “celebs”

Data:
1
Justin Bieber
21

Columns:
ID
Name
Age

Update age to 22.

A

UPDATE celebs
SET age = 22
WHERE id = 1;

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

Write a SQL command to update the following data in the table “celebs”

Data:
1
Justin Bieber
21

Columns:
ID
Name
Age

Update age to 22.

A

UPDATE celebs
SET age = 22
WHERE id = 1;

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

Write a SQL command to add a new column called “Twitter Handle” in the table named “celebs”, with the field type as text.

A

ALTER TABLE celebs ADD COLUMN [Twitter Handle] TEXT;

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

Write a SQL command to retrieve the columns “Name” and “IMDB Rating” in the table named “Movies”.

A

SELECT [Name], [IMDB_Rating] FROM [Movies];

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

Write a SQL command to retrieve the columns “Name” and IMDB Rating in the table named “Movies”.

A

SELECT [Name], [IMDB_Rating] FROM [Movies];

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

Write a SQL command to only retrieve unique values from the “Genre” column in the table named “Movies”.

A

SELECT DISTINCT [Genre] FROM [Movies];

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

Write a SQL command to retrieve movies where the “IMDB Rating” is greater than 8 in the table named “Movies”.

A

SELECT * FROM [Movies] WHERE [IMDB_Rating] > 8;

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

Write a SQL command to retrieve movie names (Name) where the movie name is like “Se*en”, where * represents any character, in the table named “Movies”.

A

SELECT * FROM [Movies] WHERE [Name] LIKE ‘Se_en’;

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

Write a SQL command to retrieve movie names (Name) where the movie name starts with “A”, in the table named “Movies”.

A

SELECT * FROM [Movies] WHERE [Name] LIKE ‘A%’;

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

Write a SQL command to retrieve movie names (Name) where the movie name ends with “a”, in the table named “Movies”.

A

SELECT * FROM [Movies] WHERE [Name] LIKE ‘%a’;

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

Write a SQL command to retrieve movie names (Name) where the movie name contains “man”, in the table named “Movies”.

A

SELECT * FROM [Movies] WHERE [Name] LIKE ‘%man%’;

17
Q

Write a SQL command to retrieve movie names (Name) where the movie name starting letter is between A and J, in the table named “Movies”;

A

SELECT * FROM [Movies] WHERE [Name] BETWEEN ‘A’ AND ‘J’;

18
Q

Write a SQL command to retrieve movie names “Name” where the movie name starting letter is between A and J, in the table named “Movies”;

A

SELECT * FROM [Movies] WHERE [Name] BETWEEN ‘A’ AND ‘J’;

19
Q

Does this SQL command retrieve movie names that start with J?

SELECT * FROM [Movies] WHERE [Name] BETWEEN ‘A’ AND ‘J’;

A

No.

20
Q

Write a SQL command to retrieve movies where the year (Year) is between 1990 and 2000.

A

SELECT * FROM [Movies] WHERE [Year] BETWEEN 1990 AND 2000;

21
Q

Write a SQL command to retrieve movies where the year “Year” is between 1990 and 2000.

A

SELECT * FROM [Movies] WHERE [Year] BETWEEN 1990 AND 2000;

22
Q

Does this SQL command retrieve movies that were released in the year 2000?

SELECT * FROM [Movies] WHERE [Year] BETWEEN 1990 AND 2000;

A

Yes.

23
Q

Write a SQL command to retrieve movies that were released between the year (Year) 1990 and 2000 and also where the genre (Genre) is comedy, in the table named “Movies”.

A

SELECT * FROM [Movies]
WHERE [Year] BETWEEN 1990 and 2000
AND [Genre] = ‘comedy’;

24
Q

Write a SQL command to retrieve movies where the genre (Genre) is comedy or if the movie was released after the year (Year) 1980, in the table named “Movies”.

A

SELECT * FROM [Movies]
WHERE [Genre] = ‘comedy’
OR [Year] < 1980;

25
Q

Write a SQL command to order the movies in descending order based on the IMDB Rating (IMDB Rating), in the table named “Movies”.

A

SELECT * FROM [Movies] ORDER BY [IMDB Rating) DESC;

26
Q

Write a SQL command to order the movies in ascending order based on the IMDB Rating (IMDB Rating), in the table named “Movies”.

A

SELECT * FROM [Movies] ORDER BY [IMDB Rating) ASC;

27
Q

Write a SQL command to return the lowest 3 rated films (IMDB Rating) in the table named “Movies”.

A

SELECT * FROM [Movies]
ORDER BY [IMDB Rating] ASC
LIMIT 3;