1.3.2D SQL Flashcards
Write a SQL command to select all the columns from the “celebs” table.
SELECT * FROM celebs;
What type of programming language is SQL?
Declarative.
What type of programming language is SQL?
Declarative
Write a SQL command to select all the columns from the “celebs” table.
SELECT * FROM celebs;
Write a SQL command to insert the following data into the table “celebs”
Data:
1
Justin Bieber
21
Columns:
ID
Name
Age
INSERT INTO celebs ([ID], [Name], [Age]) VALUES (1, ‘Justin Bieber’, 21);
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.
UPDATE celebs
SET age = 22
WHERE id = 1;
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.
UPDATE celebs
SET age = 22
WHERE id = 1;
Write a SQL command to add a new column called “Twitter Handle” in the table named “celebs”, with the field type as text.
ALTER TABLE celebs ADD COLUMN [Twitter Handle] TEXT;
Write a SQL command to retrieve the columns “Name” and “IMDB Rating” in the table named “Movies”.
SELECT [Name], [IMDB_Rating] FROM [Movies];
Write a SQL command to retrieve the columns “Name” and IMDB Rating in the table named “Movies”.
SELECT [Name], [IMDB_Rating] FROM [Movies];
Write a SQL command to only retrieve unique values from the “Genre” column in the table named “Movies”.
SELECT DISTINCT [Genre] FROM [Movies];
Write a SQL command to retrieve movies where the “IMDB Rating” is greater than 8 in the table named “Movies”.
SELECT * FROM [Movies] WHERE [IMDB_Rating] > 8;
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”.
SELECT * FROM [Movies] WHERE [Name] LIKE ‘Se_en’;
Write a SQL command to retrieve movie names (Name) where the movie name starts with “A”, in the table named “Movies”.
SELECT * FROM [Movies] WHERE [Name] LIKE ‘A%’;
Write a SQL command to retrieve movie names (Name) where the movie name ends with “a”, in the table named “Movies”.
SELECT * FROM [Movies] WHERE [Name] LIKE ‘%a’;
Write a SQL command to retrieve movie names (Name) where the movie name contains “man”, in the table named “Movies”.
SELECT * FROM [Movies] WHERE [Name] LIKE ‘%man%’;
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”;
SELECT * FROM [Movies] WHERE [Name] BETWEEN ‘A’ AND ‘J’;
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”;
SELECT * FROM [Movies] WHERE [Name] BETWEEN ‘A’ AND ‘J’;
Does this SQL command retrieve movie names that start with J?
SELECT * FROM [Movies] WHERE [Name] BETWEEN ‘A’ AND ‘J’;
No.
Write a SQL command to retrieve movies where the year (Year) is between 1990 and 2000.
SELECT * FROM [Movies] WHERE [Year] BETWEEN 1990 AND 2000;
Write a SQL command to retrieve movies where the year “Year” is between 1990 and 2000.
SELECT * FROM [Movies] WHERE [Year] BETWEEN 1990 AND 2000;
Does this SQL command retrieve movies that were released in the year 2000?
SELECT * FROM [Movies] WHERE [Year] BETWEEN 1990 AND 2000;
Yes.
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”.
SELECT * FROM [Movies]
WHERE [Year] BETWEEN 1990 and 2000
AND [Genre] = ‘comedy’;
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”.
SELECT * FROM [Movies]
WHERE [Genre] = ‘comedy’
OR [Year] < 1980;
Write a SQL command to order the movies in descending order based on the IMDB Rating (IMDB Rating), in the table named “Movies”.
SELECT * FROM [Movies] ORDER BY [IMDB Rating) DESC;
Write a SQL command to order the movies in ascending order based on the IMDB Rating (IMDB Rating), in the table named “Movies”.
SELECT * FROM [Movies] ORDER BY [IMDB Rating) ASC;
Write a SQL command to return the lowest 3 rated films (IMDB Rating) in the table named “Movies”.
SELECT * FROM [Movies]
ORDER BY [IMDB Rating] ASC
LIMIT 3;