How to remove duplicate records from the table #shorts #sql #coding #sqlqueries

preview_player
Показать описание
How to remove duplicate records from the table #shorts #sql #coding #sqlqueries #youtubeshorts #programming
Рекомендации по теме
Комментарии
Автор

with cte as ( select *, row_count() over (partition by empname order by empname) as rn from table_name )
delete from cte where rn>1

Rishikesh-cr
Автор

So simple query to ignore group by and having clause.. Thanks please keep it up.

aniketkatre
Автор

use this

delete from emp e
where exists ( select 1 from emp where empname=e.empname and empid>e.empid)

1000x times faster than your query

userzzzabc
Автор

This leetcode easy level question ..easy and medium from leetcode.is enough to crack any interview..

guiltycrown
Автор

Hi Sir, a big fan.
Why > and not = in the second where clause?

sachinsoni
Автор

This is very easy without using cte and row_number partition

Coder_Satyabrata_S
Автор

super nice solution..you just got another subscriber

snood
Автор

This was so simple, I used CTE and partition which is difficult compared with this one.

alibasha
Автор

If some employees have the same name, then how this will be work. Because employee id should be unique and we can't delete the rows based on name. That's not a meaningful one 🤔

StalPho
Автор

There is no colums e1 and e2 🤔🤔🤔are these temporary names(rows)?

p.karthik-
Автор

Duplicate records means empid too is same and not different

samidfc
Автор

That's good teaching very well I'm. Also believe that so that good ..

vlog.
Автор

Using rowid to delete duplicate records

ncrcottonbalesseeds
Автор

Why are you using e1.empid>e2.empid. could you pls explain

RakeshKumar-ywjp
Автор

Are you deleting the whole instance e1, how does it know we are deleting that particular row, is it confirming it in where Clause ?

gameply
Автор

Cool solution but we only compared name. If any other field is different for both the accounts, this approach fails.

ganeshwalunj
Автор

If we don't have Emp_id in table ? which column should take to remove duplicate employee name

RajKumar_
Автор

How to delete without using delete query??

sathyans
Автор

What's the use? Seriously these questions are asked just to polish the interviewer's ego. Why shouldn't I use group by. Db world is suddenly not going to deprecate group by tomorrow.

sathyans
Автор

SQL - Structured Query Language❌
SQL - Simplest Query Language✔️

VishwajeetVKale