sqlbeginner10 minutes
Fix the SQL Query to Correctly Filter Recent Orders
A simple SQL query intended to fetch orders placed in the last 7 days is not returning correct results. Find and fix the bug to make it functional.
Challenge prompt
The query is supposed to select all columns from the 'orders' table for orders created within the last 7 days. However, it currently returns all records regardless of the date. Identify what is wrong with the WHERE clause and fix the query so that only recent orders (past 7 days) are returned.
Guidance
- • Check the logic and data types used in the WHERE condition.
- • Review how dates and intervals are handled in SQL queries.
Hints
- • Make sure to use the correct function to get the current date/time.
- • Compare the order date with the current date minus 7 days properly.
Starter code
SELECT * FROM orders WHERE order_date > CURRENT_DATE - 7;Expected output
Only rows where 'order_date' is within the past 7 days (from today) are returned.
Core concepts
SQL date functionsWHERE clause filtering
Challenge a Friend
Send this duel to someone else and see if they can solve it.