Hi everyoune!
Retrieve film titles and their rental rates. Use column aliases to rename title as "Movie Title" and rental_rate as "Rate".
this query selects title and rental_rate from table film and renames the columns as Movie_Title and Rate.
SELECT title AS "Movie Title", rental_rate AS "Rate" FROM film;
List customer names and their email addresses. Alias first_name and last_name as "First Name" and "Last Name".
This query selects first name, last name, and emailfrom customer table and then renamed first_name as First Name and last_name as Last Name.
SELECT first_name AS "First Name", last_name AS "Last Name", email FROM customer;
Get a list of films sorted by rental rate in descending order. If two films have the same rental rate, sort them alphabetically by title.
SELECT title, rental_rate FROM film ORDER BY rental_rate DESC, title ASC;
here we select films sorted by highest rental rate first, and if same rate, sorted alphabetically by title.
Retrieve actor names sorted by last name, then first name.
SELECT first_name, last_name FROM actor ORDER BY last_name, first_name;
select actors arranged based on last name first, then first name.
List all unique replacement costs from the film table.
SELECT DISTINCT replacement_cost FROM film;
the query selects only unique replacement cost values without duplicates using distinct.
List all films' title and length in minutes. Alias length as "Duration (min)".
SELECT title, length as "Duration" FROM film;
selects title and length from table film and rename length as Duration.
Retrieve customer first and last names along with their active status. Alias active as "Is Active".
SELECT first_name, last_name, active AS "Is_Active" FROM customer;
selects customer first_name,last_name and check whether they are active or not based on column active.
Retrieve the list of film categories sorted alphabetically.
SELECT name FROM category ORDER BY name;
selects all categories sorted in alphabetical order.
List films by length, sorted in descending order. Include only the title and length
SELECT title, length FROM film ORDER BY length DESC;
selects title and length from table film and order based on length in descending.
Retrieve all actor names, sorted by their first name in descending order.
SELECT first_name, last_name FROM actor ORDER BY first_name DESC;
here the table Actors is sorted in reverse alphabetical order of first name.
List all unique ratings available in the film table
SELECT DISTINCT rating FROM film;
Select all distinct ratings fron the table film.
Find all unique rental durations from the film table.
SELECT DISTINCT rental_duration FROM film;
the query selects unique rental durations from the film table.
Retrieve the first unique customer ID based on active status. Include the customer_id and active columns, and order by customer_id.
SELECT customer_id, active FROM customer ORDER BY customer_id;
selects customer_id and active from table customer and sorted by id.
List the earliest rental date for each customer. Include customer_id and rental_date, and order by customer_id.
SELECT customer_id, MIN(rental_date) FROM rental GROUP BY customer_id ORDER BY customer_id;
selects the earliest rental date for each customer by taking average on each customer_id.
List the 10 shortest films by length. Include the title and length.
SELECT title, length FROM film ORDER BY length ASC LIMIT 10;
select first 10 films with smallest duration using limit.
Get the top 5 customers with the highest customer_id. Include the first and last name.
SELECT first_name, last_name FROM customer ORDER BY customer_id DESC LIMIT 5;
select last 5 customers with highest customer_id by ordering in descending and apply limit.
Retrieve all unique values of store_id from the inventory table.
SELECT DISTINCT store_id FROM inventory;
select all unique values of store_id from the inventory table.
Find all unique replacement_cost values in the film table. Sort the results in ascending order.
SELECT DISTINCT replacement_cost FROM film ORDER BY replacement_cost;
select all unique replacement_cost values in the film table sort in ascending order.
List the first rental date for each store. Include store_id and rental_date, and sort by store_id.
SELECT store_id, MIN(rental_date) FROM rental GROUP BY store_id ORDER BY store_id;
selects store_id,rental_date as the first rental date for each store and sort based on store_id.
Retrieve a list of film ratings sorted alphabetically and include only unique values.
SELECT DISTINCT rating FROM film ORDER BY rating;
select all unique ratings from film table in alphabetical order.
List films by rating in ascending order and length in descending order.
SELECT title,rating,length FROM film ORDER BY rating ASC,length DESC;
here the query order the film by rating in ascending order and length in descending.
Retrieve actor names sorted by last_name in ascending order and first_name in descending order.
SELECT first_name, last_name FROM actor ORDER BY last_name ASC, first_name DESC;
select first_name and last_name from table actor and Sort last_name by ascending, and reverse order of first_name.
List films ordered by replacement_cost in ascending order and rental_rate in descending order.
SELECT title, replacement_cost, rental_rate FROM film ORDER BY replacement_cost ASC, rental_rate DESC;
select columns from table film ordered by replacement_cost in ascending order and rental_rate in descending order.
Retrieve customer names sorted by last_name ascending and first_name descending.
SELECT first_name,last_name FROM customer ORDER BY last_name ASC, first_name DESC ;
select columns from table Customers sorted by last_name ascending and reverse_first name.
List all rentals sorted by customer_id ascending and rental_date descending.
SELECT * FROM rental ORDER BY customer_id ASC, rental_date DESC;
select columns from table rental sorted by customer_id ascending and rental_date descending.
Retrieve a list of films ordered by rental_duration ascending and title descending.
SELECT title, rental_duration FROM film ORDER BY rental_duration ASC, title DESC;
Top comments (0)