Day_3_SQL_Notes
Day_3_SQL_Notes
The WHERE clause allows you to filter records based on specific conditions.
Syntax:
FROM table_name
WHERE condition;
Example:
Exercise:
Syntax:
FROM table_name
Example:
SELECT * FROM books ORDER BY price DESC;
Exercise:
Example:
Exercise:
GROUP BY groups rows by common column values and is often used with aggregates.
Syntax:
FROM table_name
GROUP BY column1;
Example:
Syntax:
FROM table_name
GROUP BY column1
HAVING condition;
Example:
SELECT author, COUNT(*) AS books_count FROM books GROUP BY author HAVING COUNT(*)
> 1;
Exercise:
1. Group books by author and show only those with more than 1 book.
Scenario:
You are working with a 'books' table with columns: book_id, title, author, price.
7. Group books by author and show those with more than 2 books.