DEV Community

Luckshvadhan B
Luckshvadhan B

Posted on

Select Queries from DVD Rental database

Retrieve film titles and rental rates
Select title and rental_rate and rename them as Movie Title and Rate using aliases

List customer names and email
Select first_name last_name and email and rename names as First Name and Last Name

Sort films by rental rate descending then title
Order films by rental_rate in descending order and use title as secondary ascending sort

Sort actor names by last then first name
Order actors first by last_name then by first_name

Get unique replacement costs
Use distinct on replacement_cost to remove duplicates

List film title and duration
Select title and length and rename length as Duration min

Get customer names with active status
Select first_name last_name and active and rename active as Is Active

List film categories alphabetically
Select category names and sort them in ascending order

List films by length descending
Select title and length and sort by length in descending order

Sort actor names by first name descending
Order actors by first_name in descending order

Get unique film ratings
Use distinct on rating column to list unique values

Get unique rental durations
Use distinct on rental_duration to remove duplicates

Get first unique customer by active status
Select customer_id and active remove duplicates and order by customer_id

Get earliest rental date for each customer
Group by customer_id and get minimum rental_date then sort by customer_id

Get 10 shortest films
Order films by length ascending and limit results to 10

Get top 5 customers by highest id
Order customers by customer_id descending and limit to 5

Get unique store ids
Use distinct on store_id from inventory

Get unique replacement cost sorted
Use distinct on replacement_cost and sort in ascending order

Get first rental date per store
Group by store_id and get minimum rental_date then sort by store_id

Get unique film ratings sorted
Use distinct on rating and sort alphabetically

Sort films by rating and length
Order by rating ascending and length descending

Sort actors by last asc and first desc
Order by last_name ascending and first_name descending

Sort films by cost and rental rate
Order by replacement_cost ascending and rental_rate descending

Sort customers by last asc and first desc
Order by last_name ascending and first_name descending

Sort rentals by customer and date
Order by customer_id ascending and rental_date descending

Sort films by duration and title
Order by rental_duration ascending and title descending

Top comments (0)