DEV Community

Sharmila devi
Sharmila devi

Posted on

Select Queries from DVD Rental database

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;

List customer names and their email addresses. Alias first_name and last_name as "First Name" and "Last Name".
SELECT DISTINCT replacement_cost
FROM film;

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;

Retrieve actor names sorted by last name, then first name.
List all unique replacement costs from the film table.

SELECT first_name, last_name
FROM actor
ORDER BY last_name ASC, first_name ASC;

List all films' title and length in minutes. Alias length as "Duration (min)".
SELECT title, length AS "Duration (min)"
FROM film;

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;

Retrieve the list of film categories sorted alphabetically.
SELECT name AS "Category"
FROM category
ORDER BY name ASC;

List films by length, sorted in descending order. Include only the title and length.
SELECT title, length
FROM film
ORDER BY length DESC;

Retrieve all actor names, sorted by their first name in descending order.
SELECT first_name, last_name
FROM actor
ORDER BY first_name DESC;

List all unique ratings available in the film table.
SELECT DISTINCT rating
FROM film;

Find all unique rental durations from the film table.
SELECT DISTINCT rental_duration
FROM film;

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
GROUP BY customer_id, active
ORDER BY customer_id
LIMIT 1;

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 "Earliest Rental"
FROM rental
GROUP BY customer_id
ORDER BY 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;

Get the top 5 customers with the highest customer_id. Include the first and last name.
SELECT first_name, last_name, customer_id
FROM customer
ORDER BY customer_id DESC
LIMIT 5;

Retrieve all unique values of store_id from the inventory table.
SELECT DISTINCT store_id
FROM inventory;

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;

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 "First Rental"
FROM rental
GROUP BY store_id
ORDER BY store_id;

Retrieve a list of film ratings sorted alphabetically and include only unique values.
SELECT DISTINCT rating
FROM film
ORDER BY rating ASC;

List films by rating in ascending order and length in descending order.
SELECT title, rating, length
FROM film
ORDER BY rating ASC, length DESC;

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;

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;

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;

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;

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)