DEV Community

Jeyaprasad R
Jeyaprasad R

Posted on

CA31- Select Queries from DVD Rental database

  1. Film titles and rental rates (Aliased)
   SELECT title AS "Movie Title", rental_rate AS "Rate" 
   FROM film;
Enter fullscreen mode Exit fullscreen mode

2.Customer names and emails (Aliased)

   SELECT first_name AS "First Name", last_name AS "Last Name", email 
   FROM customer;
Enter fullscreen mode Exit fullscreen mode

3.Films sorted by rental rate (DESC) and title (ASC)

   SELECT * FROM film 
   ORDER BY rental_rate DESC, title ASC;
Enter fullscreen mode Exit fullscreen mode

4.Actor names sorted by last name, then first name

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

5.Unique replacement costs

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

6.Film title and length (Aliased)

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

7.Customer names and active status (Aliased)

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

8.Film categories sorted alphabetically

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

9.Films by length (DESC)

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

10.Actor names sorted by first name (DESC)

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

11.Unique ratings

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

12.Unique rental durations

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

13.First unique customer ID based on active status

```sql
SELECT MIN(customer_id) AS customer_id, active 
FROM customer 
GROUP BY active 
ORDER BY customer_id;
```
Enter fullscreen mode Exit fullscreen mode

14.Earliest rental date for each customer

```sql
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.10 shortest films

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

16.Top 5 customers with highest IDs

```sql
SELECT first_name, last_name 
FROM customer 
ORDER BY customer_id DESC 
LIMIT 5;
```
Enter fullscreen mode Exit fullscreen mode

17.Unique store IDs from inventory

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

18.Unique replacement costs (Sorted ASC)

```sql
SELECT DISTINCT replacement_cost 
FROM film 
ORDER BY replacement_cost ASC;
```
Enter fullscreen mode Exit fullscreen mode

19.First rental date for each store

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

20.Unique film ratings sorted alphabetically

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

21.Films by rating (ASC) and length (DESC)

```sql
SELECT * FROM film 
ORDER BY rating ASC, length DESC;
```
Enter fullscreen mode Exit fullscreen mode

22.Actor names (Last Name ASC, First Name DESC)

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

23.Films by replacement cost (ASC) and rental rate (DESC)

```sql
SELECT * FROM film 
ORDER BY replacement_cost ASC, rental_rate DESC;
```
Enter fullscreen mode Exit fullscreen mode

24.Customer names (Last Name ASC, First Name DESC)

```sql
SELECT first_name, last_name 
FROM customer 
ORDER BY last_name ASC, first_name DESC;
```
Enter fullscreen mode Exit fullscreen mode

25.Rentals (Customer ID ASC, Rental Date DESC)

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

26.Films (Rental Duration ASC, Title DESC)

```sql
SELECT * FROM film 
ORDER BY rental_duration ASC, title DESC;
```
Enter fullscreen mode Exit fullscreen mode

Top comments (0)