DEV Community

ARUL SELVI ML
ARUL SELVI ML

Posted on

BASIC QUERIES FOR SQL

1. Movies with Rental Rate Greater Than 3

```sql id="m1a2b3"
SELECT *
FROM film
WHERE rental_rate > 3;




This query returns all movies with a rental rate greater than 3.

---

## 2. Movies with Rental Rate Greater Than 3 and Replacement Cost Less Than 20



```sql id="m2b3c4"
SELECT *
FROM film
WHERE rental_rate > 3 AND replacement_cost < 20;
Enter fullscreen mode Exit fullscreen mode

This filters movies based on two conditions.


3. Movies Rated PG or Rental Rate 0.99

```sql id="m3c4d5"
SELECT *
FROM film
WHERE rating = 'PG' OR rental_rate = 0.99;




This returns movies that match at least one condition.

---

## 4. First 10 Movies Sorted by Rental Rate Highest First



```sql id="m4d5e6"
SELECT *
FROM film
ORDER BY rental_rate DESC
LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

This shows the top 10 movies with the highest rental rate.


5. Skip First 5 and Get Next 3 Movies

```sql id="m5e6f7"
SELECT *
FROM film
ORDER BY rental_rate ASC
OFFSET 5
LIMIT 3;




This skips the first 5 records and returns the next 3.

---

## 6. Skip First 5 and Get Next 3 Movies



```sql id="m6f7g8"
SELECT *
FROM film
ORDER BY rental_rate ASC
OFFSET 5
LIMIT 3;
Enter fullscreen mode Exit fullscreen mode

This is the same as the previous query.


7. Movies with Rental Duration Between 3 and 7 Days

```sql id="m7g8h9"
SELECT *
FROM film
WHERE rental_duration BETWEEN 3 AND 7;




This filters movies within a range.

---

## 8. Movies with Title Starting with A and Ending with e



```sql id="m8h9i0"
SELECT *
FROM film
WHERE title LIKE 'A%e';
Enter fullscreen mode Exit fullscreen mode

This uses pattern matching.


9. Customers Without Email Address

```sql id="m9i0j1"
SELECT *
FROM customer
WHERE email IS NULL;




This finds missing values.

---

## 10. Movies Released in 2006 with Specific Rates and Title Starting with S



```sql id="m0j1k2"
SELECT title, rental_rate, release_year
FROM film
WHERE release_year = 2006
AND rental_rate IN (2.99, 3.99)
AND title LIKE 'S%'
LIMIT 5;
Enter fullscreen mode Exit fullscreen mode

This applies multiple filters and limits results.


11. Display 10 Customers After Skipping First 20

```sql id="n1k2l3"
SELECT *
FROM customer
ORDER BY last_name
OFFSET 20
LIMIT 10;




This shows paginated results.

---

## 12. Top 5 Movies by Replacement Cost Skipping Highest One



```sql id="n2l3m4"
SELECT *
FROM film
ORDER BY replacement_cost DESC
OFFSET 1
LIMIT 5;
Enter fullscreen mode Exit fullscreen mode

This skips the most expensive movie and shows the next five.


13. Rentals Between Two Dates

```sql id="n3m4n5"
SELECT *
FROM rental
WHERE rental_date BETWEEN '2005-05-01' AND '2005-06-01';




This filters data by date range.

---

## 14. Actors with Last Name Containing "man"



```sql id="n4n5o6"
SELECT *
FROM actor
WHERE last_name LIKE '%man%';
Enter fullscreen mode Exit fullscreen mode

This finds patterns in text.


15. Movies with No Special Features

```sql id="n5o6p7"
SELECT *
FROM film
WHERE special_features IS NULL;




This finds records with missing values.

---

## 16. Movies with Rental Duration More Than 7 Days



```sql id="n6p7q8"
SELECT *
FROM film
WHERE rental_duration > 7;
Enter fullscreen mode Exit fullscreen mode

This filters based on numeric condition.


17. First 10 Movies with Multiple Conditions

```sql id="n7q8r9"
SELECT *
FROM film
WHERE rental_rate IN (2.99, 4.99)
AND rating = 'R'
AND title LIKE '%L%'
LIMIT 10;




This combines multiple conditions.

---

## 18. Movies Starting with A or B and Ending with s



```sql id="n8r9s0"
SELECT *
FROM film
WHERE (title LIKE 'A%s' OR title LIKE 'B%s');
Enter fullscreen mode Exit fullscreen mode

This uses multiple pattern conditions.


19. Movies Containing Man, Men, or Woman

```sql id="n9s0t1"
SELECT *
FROM film
WHERE title LIKE '%Man%'
OR title LIKE '%Men%'
OR title LIKE '%Woman%';




This finds movies with specific words in the title.


Enter fullscreen mode Exit fullscreen mode

Top comments (0)