Delete Duplicate Emails and select Patients With a Condition SQL MySQL Leetcode Solution

Опубликовано: 13 Март 2026
на канале: CodeWis Technologies by Nuhman Paramban
11
1

Selecting Patients with Specific Conditions
sql
Copy code
select *
from Patients
where conditions like '% DIAB1%' or
conditions like 'DIAB1%';
Purpose: This query selects all records from the Patients table where the conditions column contains a substring starting with "DIAB1". The condition '% DIAB1%' ensures that it matches "DIAB1" even if there are other words before it, while like 'DIAB1%' matches if it is at the beginning.

Deleting Duplicate emails from Person
sql
Copy code
DELETE from Person where Id not in
(select id from (select min(Id) as Id
from Person group by Email ) as p);
Purpose: This query deletes records from the Person table where the id is not the minimum id for each email. This removes duplicate emails, leaving only the record with the smallest id for each email.