Retrieve film titles and their rental rates. Use column aliases to rename title as "Movie Title" and rental_rate as "Rate".
SELECT title AS "Movie Title" , rental_rate AS "Rate" FROM film;
Meaning : Changing the name of the column title as Movie Title and rental_rate as Rate From film table
List customer names and their email addresses. Alias first_name and last_name as "First Name" and "Last Name".
SELECT first_name AS "First Name", last_name AS "Last Name" FROM customer;
SELECT first_name , last_name , email FROM customer;
Meaning : Return only first name , last name and email from the customer table
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;
Meaning : Return title and rental_rate from film table and rental_rate by descending , title by sorted
Retrieve actor names sorted by last name, then first name.
SELECT first_name, last_name FROM actor ORDER BY last_name ASC, first_name ASC;
Meaning : Return last_name and first_name from film table by ascending order
List all unique replacement costs from the film table.
SELECT DISTINCT replacement_cost FROM film;
Meaning : Return all non-duplicate values from film table
List all films' title and length in minutes. Alias length as "Duration
(min)".
SELECT title, length AS "Duration (min)" FROM film;
Meaning : Return title and change length name as Duration(min) from film table
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;
Meaning : Return first_name , last_name and active status change as Active from customer table
Retrieve the list of film categories sorted alphabetically.
SELECT name AS "Category" FROM category ORDER BY name ASC;
Meaning : Return name change as category and arrange in ascending order
List films by length, sorted in descending order. Include only the title and length.
SELECT title, length FROM film ORDER BY length DESC;
Meaning : Return title and length from film table and sort length in descending order (longest films first)
Retrieve all actor names, sorted by their first name in descending order.
SELECT first_name, last_name FROM actor ORDER BY first_name DESC;
Meaning : Return first_name and last_name from actor table and sort by first_name in descending order
List all unique ratings available in the film table.
SELECT DISTINCT rating FROM film;
Meaning : Return all unique (non-duplicate) ratings from film table
Find all unique rental durations from the film table.
SELECT DISTINCT rental_duration FROM film;
Meaning : Return all unique rental_duration values from 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 LIMIT 1;
Meaning : Return first customer_id and active status from customer table based on ascending order
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) AS rental_date FROM rental GROUP BY customer_id ORDER BY customer_id;
*Meaning : Return customer_id and earliest rental_date for each customer using MIN function
*
List the 10 shortest films by length. Include the title and length.
SELECT title, length FROM film ORDER BY length ASC LIMIT 10;
**
**Meaning : Return 10 films with shortest length from film table
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;
Meaning : Return top 5 customers with highest customer_id sorted in descending order
Retrieve all unique values of store_id from the inventory table.
SELECT DISTINCT store_id FROM inventory;
Meaning : Return all unique store_id values from 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 ASC;
*Meaning : Return unique replacement_cost values sorted 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) AS rental_date FROM rental GROUP BY store_id ORDER BY store_id;
Meaning : Return earliest rental_date for each store using MIN function
Retrieve a list of film ratings sorted alphabetically and include only unique values.
SELECT DISTINCT rating FROM film ORDER BY rating ASC;
Meaning : Return unique film ratings sorted alphabetically
List films by rating in ascending order and length in descending order.
SELECT title, rating, length FROM film ORDER BY rating ASC, length DESC;
*Meaning : Return films sorted by rating (ascending) and length (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;
**
**Meaning : Return actor names sorted by last_name ascending and first_name descending
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;
Meaning : Return films sorted by replacement_cost ascending and rental_rate descending
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;
Meaning : Return customer names sorted by last_name ascending and first_name descending
List all rentals sorted by customer_id ascending and rental_date descending.
SELECT customer_id, rental_date FROM rental ORDER BY customer_id ASC, rental_date DESC;
Meaning : Return rentals 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;
Meaning : Return films sorted by rental_duration ascending and title descending
Top comments (0)