DEV Community

Abirami Prabhakar
Abirami Prabhakar

Posted on

Select Queries from DVD Rental database

1.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_rates as "Rate"
FROM film;
Enter fullscreen mode Exit fullscreen mode

2.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",
       email 
FROM customer;
Enter fullscreen mode Exit fullscreen mode

3.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 title ASC, rental_rate DSC;
Enter fullscreen mode Exit fullscreen mode

4.Retrieve actor names sorted by last name, then first name.

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

Enter fullscreen mode Exit fullscreen mode

5.List all unique replacement costs from the film table.

SELECT DISTINCT replacement_cost
FROM film;
Enter fullscreen mode Exit fullscreen mode

6.List all films' title and length in minutes. Alias length as "Duration (min)".

SELECT title,
length as "Duration(min)"
FROM film
Enter fullscreen mode Exit fullscreen mode

7.Retrieve customer first and last names along with their active status. Alias active as "Is Active".

SELECT first_name,
        last_name,
        active is "Is Active"
FROM customer;
Enter fullscreen mode Exit fullscreen mode

8.Retrieve the list of film categories sorted alphabetically.

SELECT name
FROM category
ORDER BY name; 
Enter fullscreen mode Exit fullscreen mode

9.List films by length, sorted in descending order. Include only the title and length.

SELECT title, length
FROM film
ORDER BY length DESC;
Enter fullscreen mode Exit fullscreen mode

10.Retrieve all actor names, sorted by their first name in descending order.

SELECT first_name, last_name
FROM actor
ORDER BY first_name DESC;
Enter fullscreen mode Exit fullscreen mode

11.List all unique ratings available in the film table.

SELECT DISTINCT rating
FROM film;
Enter fullscreen mode Exit fullscreen mode

12.Find all unique rental durations from the film table.

SELECT DISTINCT rental_duration
FROM film;
Enter fullscreen mode Exit fullscreen mode

13.Retrieve the first unique customer ID based on active status. Include the customer_id and active columns, and order by customer_id.

SELECT DISTINCT customer_id, active
FROM customer
ORDER BY customer_id;
Enter fullscreen mode Exit fullscreen mode

14.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;
Enter fullscreen mode Exit fullscreen mode

15.List the 10 shortest films by length. Include the title and length.

SELECT title, length
FROM film
ORDER BY length ASC
LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

16.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;
Enter fullscreen mode Exit fullscreen mode

17.Retrieve all unique values of store_id from the inventory table.

SELECT DISTINCT store_id
FROM inventory;
Enter fullscreen mode Exit fullscreen mode

18.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;
Enter fullscreen mode Exit fullscreen mode

19.List the first rental date for each store. Include store_id and rental_date, and sort by store_id.

SELECT i.store_id,
       MIN(r.rental_date) AS rental_date
FROM rental r
JOIN inventory i ON r.inventory_id = i.inventory_id
GROUP BY i.store_id
ORDER BY i.store_id;
Enter fullscreen mode Exit fullscreen mode

20.Retrieve a list of film ratings sorted alphabetically and include only unique values.

SELECT DISTINCT rating
FROM film
ORDER BY rating;
Enter fullscreen mode Exit fullscreen mode

21.List films by rating in ascending order and length in descending order.

SELECT title, rating, length
FROM film
ORDER BY rating ASC, length DESC;
Enter fullscreen mode Exit fullscreen mode

22.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;
Enter fullscreen mode Exit fullscreen mode

23.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;
Enter fullscreen mode Exit fullscreen mode

24.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;
Enter fullscreen mode Exit fullscreen mode

25.List all rentals sorted by customer_id ascending and rental_date descending.

SELECT *
FROM rental
ORDER BY customer_id ASC, rental_date DESC;
Enter fullscreen mode Exit fullscreen mode

26.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;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)