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;
Here,title is renamed into Movie Title amd rental_rate is renamed into Rate from film table and to show the output.
List customer names and their email addresses. Alias first_name and last_name as "First Name" and "Last Name".
SELECT first_name AS "First Name",last_name AS "Last Name",email FROM customer;
Here, first_name is ranamed into First Name and last_name as Last Name and fetch the email from the customer table.
Get a list of films sorted by rental rate in descending order. If two films have the same rental rate, sort them alphabetically by title.
SELECT title,rental_rate FROM film ORDER BY rental_rate DESC,title ASC;
Here, title and rental_rate to be fetch from film table and to order the rental_rate to descending order and title as ascending order.
Retrieve actor names sorted by last name, then first name.
SELECT first_name,last_nameFROM actor ORDER BY last_name ASC,first_name ASC;
Here, the first_name and last_name to be fetch from actor table and to order the last name and first name in asccending order.
List all unique replacement costs from the film table.
SELECT DISTINCT replacement_cost FROM film;
Here, the we need to fetch the unique replacement_cost from the film table so we used DISTINCT in the query.
List all films' title and length in minutes. Alias length as "Duration (min)".
SELECT title,length AS "Duration (min)"FROM film;
Here, from film table the title and the length data to be fetch and to rename the length as Duration(min) so we use length AS "Duration (min)".
Retrieve customer first and last names along with their active status. Alias active as "Is Active".
SELECT first_name,last_name,active AS "Is Active" FROM customer;
Here,the first_name, last_name and active from customer table and to rename the active to Is Active so we use active AS "Is Active".
Retrieve the list of film categories sorted alphabetically.
SELECT name from category order by name ASC;
Here, to take the list of film name from caregory and to sort the film name in ascending order.
List films by length, sorted in descending order. Include only the title and length.
SELECT title lenght FROM film ORDER BY title DESC,length DESC;
Here, list all the title and length from film and to order the title and lenght by descending order.
Retrieve all actor names, sorted by their first name in descending order.
SELECT first_name FROM actor ORDER BY first_name DESC;
Here,from actor table the first_name to be fetch and to order it by descending order.
List all unique ratings available in the film table.
SELECT DISTINCT rating FROM film;
Here,for the unique rating we are using DISTINCT to get unique rating from film table.
Find all unique rental durations from the film table.
SELECT DISTINCT rental_duration FROM film;
Here,for the unique rental_duation we are using DISTINCT to get unique rental_duration from film table.
Retrieve the first unique customer ID based on active status. Include the customer_id and active columns, and order by customer_id.
SELECT DISTINCT ON (active)customer_id,active FROM customer ORDER BY active,customer_id;
Here,we are fetching the data from customer which must give unique customer_id which must be active that means this query gives the customer_id which are in active.
List the earliest rental date for each customer. Include customer_id and rental_date, and order by customer_id.
SELECT customer_id,MIN(rental_date) AS rental_date FROM rental GROUP BY customer_id ORDER BY customer_id;
Here, we need to fetch the earliest rental data so we are using MIN(rental_date) and also including the customer_id and rental_date which must be in the order of customer_id from rental table.
List the 10 shortest films by length. Include the title and length.
SELECT title,length FROM film LIMIT 10;
Here, we need to fetch the title, length from the film table and it should be shortest of 10 films so using LIMIt 10.
Retrieve all unique values of store_id from the inventory table.
SELECT DISTINCT store_id FROM inventory;
Here, we need to fetch unique store_id from inventory table so we are using DISTINCT store_id.
Find all unique replacement_cost values in the film table. Sort the results in ascending order.
SELECT DISTINCT replacement_cost FROM film ORDER BY replacement_cost ASC;

















Top comments (0)