I retrieved film titles and their rental rates. I used column aliases to make the output more readable. Instead of showing column names like title and rental_rate, I renamed them to "Movie Title" and "Rate".
SELECT title AS "Movie Title", rental_rate AS "Rate"
FROM film;
Next, I listed customer names along with their email addresses. I renamed first_name and last_name to "First Name" and "Last Name".
SELECT first_name AS "First Name", last_name AS "Last Name", email
FROM customer;
I retrieved films sorted by rental rate in descending order. If two films had the same rental rate, I sorted them alphabetically by title.
SELECT title, rental_rate
FROM film
ORDER BY rental_rate DESC, title ASC;
I also sorted actor names by last name first and then by first name.
SELECT first_name, last_name
FROM actor
ORDER BY last_name, first_name;
To understand unique values, I used DISTINCT. I listed all unique replacement costs and ratings from the film table.
SELECT DISTINCT replacement_cost
FROM film;
SELECT DISTINCT rating
FROM film
ORDER BY rating;
I also retrieved film titles along with their length and renamed the length column.
SELECT title, length AS "Duration (min)"
FROM film;
Then I checked customer details with their active status.
SELECT first_name, last_name, active AS "Is Active"
FROM customer;
I explored categories and sorted them alphabetically.
SELECT name
FROM category
ORDER BY name;
I listed films by length in descending order.
SELECT title, length
FROM film
ORDER BY length DESC;
I also sorted actor names in reverse order based on first name.
SELECT first_name, last_name
FROM actor
ORDER BY first_name DESC;
To find unique rental durations, I used DISTINCT again.
SELECT DISTINCT rental_duration
FROM film;
I retrieved the first customer based on active status.
SELECT customer_id, active
FROM customer
ORDER BY customer_id
LIMIT 1;
I also retrieved the earliest rental date for each customer.
SELECT customer_id, MIN(rental_date) AS rental_date
FROM rental
GROUP BY customer_id
ORDER BY customer_id;
Next, I found the shortest films by length.
SELECT title, length
FROM film
ORDER BY length
LIMIT 10;
I retrieved the top 5 customers with the highest IDs.
SELECT first_name, last_name
FROM customer
ORDER BY customer_id DESC
LIMIT 5;
I checked unique store IDs from the inventory table.
SELECT DISTINCT store_id
FROM inventory;
I also sorted replacement costs in ascending order.
SELECT DISTINCT replacement_cost
FROM film
ORDER BY replacement_cost;
Then I found the first rental date for each store.
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;
I sorted films by rating and then by length.
SELECT title, rating, length
FROM film
ORDER BY rating ASC, length DESC;
SELECT first_name, last_name
FROM actor
ORDER BY last_name ASC, first_name DESC;
I sorted films by replacement cost and rental rate.
SELECT title, replacement_cost, rental_rate
FROM film
ORDER BY replacement_cost ASC, rental_rate DESC;
I sorted customer names.
SELECT first_name, last_name
FROM customer
ORDER BY last_name ASC, first_name DESC;
I sorted rentals.
SELECT *
FROM rental
ORDER BY customer_id ASC, rental_date DESC;
Finally, I listed films sorted by rental duration and title.
SELECT title, rental_duration
FROM film
ORDER BY rental_duration ASC, title DESC;
Top comments (0)