0
0
SQLquery~30 mins

WHERE with OR operator in SQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Filtering Data Using WHERE with OR Operator
📖 Scenario: You are managing a small bookstore database. You want to find books that are either by a specific author or belong to a certain genre.
🎯 Goal: Build an SQL query that selects books where the author is either 'J.K. Rowling' or the genre is 'Fantasy'.
📋 What You'll Learn
Create a table called books with columns id, title, author, and genre
Insert exactly 5 rows with specified values
Write a SELECT query using WHERE with OR to filter books by author or genre
Use exact column and table names as specified
💡 Why This Matters
🌍 Real World
Filtering data with multiple conditions is common in databases for reports, searches, and data analysis.
💼 Career
Knowing how to use WHERE with OR helps in writing flexible queries for business intelligence, software development, and data management roles.
Progress0 / 4 steps
1
Create the books table and insert data
Write SQL statements to create a table called books with columns id (integer), title (text), author (text), and genre (text). Then insert these 5 rows exactly: (1, 'Harry Potter and the Sorcerer''s Stone', 'J.K. Rowling', 'Fantasy'), (2, 'The Hobbit', 'J.R.R. Tolkien', 'Fantasy'), (3, '1984', 'George Orwell', 'Dystopian'), (4, 'To Kill a Mockingbird', 'Harper Lee', 'Classic'), (5, 'The Casual Vacancy', 'J.K. Rowling', 'Drama').
SQL
Need a hint?

Use CREATE TABLE to define the table and INSERT INTO with multiple rows to add data.

2
Set up the SELECT query base
Write the beginning of a SELECT query that selects all columns from the books table. Use SELECT * and FROM books.
SQL
Need a hint?

Use SELECT * to get all columns and FROM books to specify the table.

3
Add the WHERE clause with OR operator
Add a WHERE clause to the SELECT query that filters rows where the author is 'J.K. Rowling' or the genre is 'Fantasy'. Use the OR operator exactly as shown.
SQL
Need a hint?

Use WHERE followed by the condition with OR to filter rows.

4
Complete the query with a semicolon
Add a semicolon ; at the end of the SELECT query to complete the SQL statement.
SQL
Need a hint?

SQL statements end with a semicolon ;. Make sure to add it at the end.