SQL Tutorial 01: Write a query to delete table 1 year data in SQL ?
To delete December 2024 data from a table, assuming you have a date column (e.g., CreatedDate
or OrderDate
), you can use the DELETE
statement with a WHERE
clause to filter records from December 2024.
Query Example
DELETE FROM YourTableName
WHERE CreatedDate >= '2024-12-01'
AND CreatedDate < '2025-01-01';
Explanation:
CreatedDate >= '2024-12-01'
→ Includes all records from December 1, 2024.CreatedDate < '2025-01-01'
→ Ensures only data from December 2024 is deleted.- It works for datetime, date, and timestamp columns.
Alternative: If only the Year and Month are stored separately
If the table stores Year and Month as separate columns:
DELETE FROM YourTableName
WHERE YearColumn = 2024 AND MonthColumn = 12;
Caution Before Deleting
- Run a
SELECT
query first to preview what will be deleted:SELECT * FROM YourTableName WHERE CreatedDate >= '2024-12-01' AND CreatedDate < '2025-01-01';
- Backup your data if deletion is critical.
If you like comment and share. 🚀
0 Comments