Spaces:
Sleeping
Sleeping
File size: 1,118 Bytes
49bd31a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | -- ============================================================
-- Supabase SQL: Remove Duplicate Courses
-- ============================================================
-- Logic:
-- 1. Group courses by EXACT title
-- 2. Within each group, KEEP the row with the oldest created_at
-- 3. DELETE all other duplicates
--
-- Run this in Supabase SQL Editor.
-- ============================================================
-- STEP 1: Preview duplicates (DRY RUN — won't delete anything)
-- Uncomment and run this first to see what will be removed:
-- SELECT id, title, created_at
-- FROM courses
-- WHERE id NOT IN (
-- SELECT DISTINCT ON (title) id
-- FROM courses
-- ORDER BY title, created_at ASC
-- )
-- ORDER BY title, created_at;
-- STEP 2: Delete duplicates (KEEP oldest record per title)
DELETE FROM courses
WHERE id NOT IN (
SELECT DISTINCT ON (title) id
FROM courses
ORDER BY title, created_at ASC
);
-- STEP 3: Verify — should return exactly 26 unique courses
SELECT count(*) AS total_courses FROM courses;
SELECT id, title, created_at FROM courses ORDER BY created_at ASC;
|