Instagram
youtube
Facebook
Twitter

Retrieve Orders from the Last 30 Days in SQL

Retrieve Orders from the Last 30 Days in SQL

Orders Table:

Query Explanation:

SELECT * → Retrieves all columns from the result.

FROM Orders → The data is fetched from the Orders table.

WHERE OrderDate >= CURDATE() - INTERVAL 30 DAY
→ Filters only the orders where the order date is within the last 30 days from today.
CURDATE() gives today’s date, and INTERVAL 30 DAY subtracts 30 days.

SQL Query:

USE SalesInventoryDB;

SELECT *  
FROM Orders  
WHERE OrderDate >= CURDATE() - INTERVAL 30 DAY;

 

Output: