Qn 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_rate AS "Rate" FROM film;
Picked only required columns and used aliases to make output more readable. No ordering or filtering needed since question is direct.
Qn 2: List customer names and their email addresses. Alias first_name and last_name.
SELECT first_name AS "First Name", last_name AS "Last Name", email FROM customer;
Selected identity-related fields and renamed them for clarity. Email already meaningful so kept as is.
Qn 3: Get films sorted by rental rate descending, then by title ascending.
SELECT rental_rate, title FROM film ORDER BY rental_rate DESC, title ASC;
Sorting priority is rental rate, so applied DESC first. Used title as secondary sort to handle equal values.
Qn 4: Retrieve actor names sorted by last name, then first name.
SELECT first_name, last_name FROM actor ORDER BY last_name, first_name;
Chose ordering based on common naming convention. Ensured consistency by applying secondary sort.
Qn 5: List all unique replacement costs.
SELECT DISTINCT replacement_cost FROM film;
Used DISTINCT to avoid repeated values. Only one column needed so query kept minimal.
Qn 6: List film title and length with alias.
SELECT title, length AS "Duration (min)" FROM film;
Renamed length to give context of unit. No transformation required, just presentation change.
Qn 7: Retrieve customer names with active status.
SELECT first_name, last_name, active AS "Is Active" FROM customer;
Included status column and renamed it for better readability. Combined with names for meaningful output.
Qn 8: Retrieve film categories sorted alphabetically.
SELECT name FROM category ORDER BY name;
Single column retrieval with alphabetical ordering. Default ASC works without explicitly mentioning.
Qn 9: List films by length descending.
SELECT title, length FROM film ORDER BY length DESC;
Wanted longest films first, so used DESC. Selected only relevant columns for simplicity.
Qn 10: Retrieve actor names sorted by first name descending.
SELECT first_name FROM actor ORDER BY first_name DESC;
Focused only on first names and reversed alphabetical order. No need for additional columns.
Qn 11: List all unique ratings.
SELECT DISTINCT rating FROM film;
Ensured no duplicate ratings appear. Keeps result clean and compact.
Qn 12: Find all unique rental durations.
SELECT DISTINCT rental_duration FROM film;
Same approach as ratings, applied DISTINCT. Focused only on unique duration values.
Qn 13: Retrieve first unique customer_id based on active status.
SELECT customer_id, active FROM customer ORDER BY customer_id;
Ordered by ID so smallest appears first. Included active column to match requirement.
Qn 14: List earliest rental date for each customer.
SELECT customer_id, MIN(rental_date) FROM rental GROUP BY customer_id ORDER BY customer_id;
Grouped records by customer to isolate each one. Used MIN to extract earliest date.
Qn 15: List 10 shortest films by length.
SELECT title, length FROM film ORDER BY length ASC LIMIT 10;
Ascending order brings smallest lengths first. Limited results to only top 10.
Qn 16: Get top 5 customers with highest customer_id.
SELECT first_name, last_name FROM customer ORDER BY customer_id DESC LIMIT 5;
Descending order ensures highest IDs first. LIMIT restricts output to required count.
Qn 17: Retrieve unique store_ids from inventory.
SELECT DISTINCT store_id FROM inventory;
Removed duplicates using DISTINCT. Only one column needed so query stays simple.
Qn 18: Unique replacement_cost sorted ascending.
SELECT DISTINCT replacement_cost FROM film ORDER BY replacement_cost ASC;
Combined uniqueness with ordering. ASC gives lowest values first.
Qn 19: First rental date for each store.
SELECT store_id, MIN(rental_date) FROM rental GROUP BY store_id ORDER BY store_id;
Grouped by store to separate records. Used MIN to get earliest date per group.
Qn 20: Unique film ratings sorted alphabetically.
SELECT DISTINCT rating FROM film ORDER BY rating;
Ensured uniqueness first, then sorted. Alphabetical order improves readability.
Qn 21: List films by rating ascending and length descending.
SELECT rating, length FROM film ORDER BY rating ASC, length DESC;
Applied primary sort on rating. Used length as secondary descending sort.
Qn 22: Retrieve actor names sorted by last_name ASC and first_name DESC.
SELECT first_name, last_name FROM actor ORDER BY last_name ASC, first_name DESC;
Sorted last names normally and reversed first names. Mixed ordering applied carefully.
Qn 23: List films ordered by replacement_cost ASC and rental_rate DESC.
SELECT replacement_cost, rental_rate FROM film ORDER BY replacement_cost ASC, rental_rate DESC;
Sorted cheaper films first. Within same cost, prioritized higher rental rates.
Qn 24: Retrieve customer names sorted by last_name ASC and first_name DESC.
SELECT first_name, last_name FROM customer ORDER BY last_name ASC, first_name DESC;
Used last name as primary sorting key. Applied reverse order for first names.
Qn 25: List rentals sorted by customer_id ASC and rental_date DESC.
SELECT * FROM rental ORDER BY customer_id ASC, rental_date DESC;
Grouped by customer order. Latest rentals appear first within each group.
Qn 26: Retrieve films ordered by rental_duration ASC and title DESC.
SELECT title, rental_duration FROM film ORDER BY rental_duration ASC, title DESC;
Shorter durations prioritized first. Titles reversed to handle equal durations.
Top comments (0)