MySQL + SQL · Lesson 1
Records Last 7 Days
Recent Records
To get rows created in the last 7 days, compare the date column with the date 7 days ago using DATE_SUB.
The Query
SELECT * FROM orders
WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL 7 DAY);
How it Works
DATE_SUB(CURDATE(), INTERVAL 7 DAY) gives the date 7 days ago. Any row with a newer date is from the last week.Summary
- Use
created_at >= DATE_SUB(CURDATE(), INTERVAL 7 DAY). - Change 7 to any number of days you need.
💻 Live Code Editor
Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.