-- Remove duplicate records from tablo_access table
-- Keep only the earliest record (lowest id) for each (tablo_id, user_id) combination
DELETE FROM tablo_access
WHERE id NOT IN (
    SELECT MIN(id)
    FROM tablo_access
    GROUP BY tablo_id, user_id
);

-- Add unique constraint to prevent duplicate access records
ALTER TABLE tablo_access
ADD CONSTRAINT unique_tablo_access 
    UNIQUE (tablo_id, user_id);

