let's see about different queries and how it works
1. Retrieve Film Titles and Rental Rates
SELECT title "Movie Title", rental_rate "Rate" FROM film;
Explanation
here I ma doing title is renamed as "Movie Name" and rental_rate is renamed as rate
here why I use string----> when you give space without using string it does not exists.
here without AS or with As no problem both is acceptable
2. Retrieve Customer Names and Email
Query
SELECT first_name "First Name", last_name "Last Name", email FROM customer;
Explanation
first_name is renamed to "First Name". and last_name is renamed to "Last Name".
email is left unchanged because it is already clear.
3.Films sorted by rental rate (descending), then title
SELECT title, rental_rate FROM film ORDER BY rental_rate DESC, title ASC;
Explanation
DESC is for highest first and ASC is for alphabetical.
Used for ranking + tie-breaking.
4. Actor names sorted by last name, then first name
SELECT first_name, last_name FROM actor ORDER BY last_name, first_name;
Explanation:
Standard way to sort names .
5. Unique replacement costs
SELECT DISTINCT replacement_cost FROM film;
Explanation:
Distinct removes duplicates is useful for analysis.
6. Film title and duration
select title, length AS "Duration (min)" FROM film;
Explanation:
Alias makes unit clear.
**
- Customer active status** SELECT first_name, last_name, active AS "Is Active" FROM customer;
Explanation:
Boolean values become user-friendly labels.
8. Film categories alphabetically
SELECT name FROM category ORDER BY name;
Explanation:
Sorting improves readability.
9. Films sorted by length (descending)
SELECT title, length FROM film ORDER BY length DESC;
Explanation:
Find longest movies quickly.
10. Actor names sorted by first name (descending)
SELECT first_name, last_name FROM actor ORDER BY first_name DESC;
explanation:
Reverse sorting for different views.
**
- Unique ratings**
SELECT DISTINCT rating FROM film;
explanation:
Know all available categories (PG, R, etc.).
12. Unique rental durations
SELECT DISTINCT rental_duration FROM film;
explanation:
Understand available rental plans.
13. First unique customer by active status
SELECT DISTINCT customer_id, active FROM customer ORDER BY customer_id;
explanation:
Combining DISTINCT + ORDER BY helps identify unique records in order.
**
- Earliest rental date for each customer**
SELECT customer_id, MIN(rental_date) AS first_rental FROM rental GROUP BY customer_id ORDER BY customer_id;
explanation:
GROUP BY groups data MIN() used to finds earliest value
15. 10 shortest films
SELECT title, length FROM film ORDER BY length ASC LIMIT 10;
explanation:
LIMIT restricts output of useful for top/bottom lists.
16. Top 5 customers
SELECT first_name, last_name FROM customer ORDER BY customer_id DESC LIMIT 5;
explanation:
It is used to find latest or highest records.
**
- Unique store ID**s
SELECT DISTINCT store_id FROM inventory;
explanation:
Identify all store locations.
**
- Unique replacement cost (sorted)**
SELECT DISTINCT replacement_cost FROM film ORDER BY replacement_cost ASC;
explanation:
Sorting helps in analysis.
19. First rental date for each store
SELECT store_id, MIN(rental_date) AS first_rental FROM rental GROUP BY store_id ORDER BY store_id;
explanation:
Track store activity start.
20. Unique ratings sorted
SELECT DISTINCT rating FROM film ORDER BY rating;
explanation:
Cleaner categorized output.
21. Films by rating and length
SELECT title, rating, length FROM film ORDER BY rating ASC, length DESC;
explanation:
Multi-level sorting.
*22. Actor names sorted *
SELECT first_name, last_name FROM actor ORDER BY last_name ASC, first_name DESC;
explanation:
Advanced sorting combinations.
23. Films by replacement cost and rental rate
SELECT title, replacement_cost, rental_rate FROM film ORDER BY replacement_cost ASC, rental_rate DESC;
explanation:
Useful for pricing analysis.
24. Customers sorted by name
SELECT first_name, last_name FROM customer ORDER BY last_name ASC,first_name DESC;
explanation:
Readable listing format.
25. Rentals sorted by customer and date
SELECT *FROM rental ORDER BY customer_id ASC, rental_date DESC;
explanation:
See latest activity per customer.
26. Films by rental duration and title
SELECT title, rental_duration FROM film ORDER BY rental_duration ASC, title DESC;
explanation:
Helps compare short vs long rental plans.


Top comments (0)