Using Subqueries with EXISTS in MySQL
📖 Scenario: You are managing a small online bookstore database. You want to find authors who have written books that are currently in stock.
🎯 Goal: Build a MySQL query using a subquery with EXISTS to find all authors who have at least one book available in stock.
📋 What You'll Learn
Create a table called
authors with columns author_id and author_name.Create a table called
books with columns book_id, title, author_id, and in_stock.Write a query using
EXISTS to select authors who have books with in_stock greater than 0.💡 Why This Matters
🌍 Real World
Bookstores and libraries often need to find authors who have available books for sale or loan. Using EXISTS helps efficiently check related data.
💼 Career
Database developers and analysts use subqueries with EXISTS to filter data based on related tables, a common task in real-world SQL querying.
Progress0 / 4 steps