How to Identify and Delete Duplicate Records in SQL | Easy Explanation with Real Time Scenarios

  Рет қаралды 23,874

Ankit Bansal

Ankit Bansal

Күн бұрын

In this video we will discuss how to delete duplicate rows in SQL. We will discuss multiple scenarios and different ways to delete duplicate data.
Zero to hero(Advance) SQL Aggregation:
• All About SQL Aggregat...
Most Asked Join Based Interview Question:
• Most Asked SQL JOIN ba...
Solving 4 Trick SQL problems:
• Solving 4 Tricky SQL P...
Data Analyst Spotify Case Study:
• Data Analyst Spotify C...
Top 10 SQL interview Questions:
• Top 10 SQL interview Q...
Interview Question based on FULL OUTER JOIN:
• SQL Interview Question...
Playlist to master SQL :
• Complex SQL Questions ...
Rank, Dense_Rank and Row_Number:
• RANK, DENSE_RANK, ROW_...
#sql #duplicate #data

Пікірлер: 63
@soumyagobbani5336
@soumyagobbani5336 Жыл бұрын
Great explanation on different approaches of deleting duplicates. How to delete duplicates without creating backup table when there are duplicates with exact same rows. Below would give an error saying cte does not exist. with cte as (select *, row_number() over(partition by emp_id order by emp_id) rwn from employee) delete from cte where rwn > 1
@PRASANNA170296
@PRASANNA170296 3 ай бұрын
cte is a temporary table, that you have created in this query, it doesnt have existence unlike employee table, thats why you cant delete records from it
@avi8016
@avi8016 Жыл бұрын
Great video sir💯 Most of the time I have faced duplication issues with entire row So I used row_number to take care of that
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thanks for sharing
@ShreyaMishra0307__
@ShreyaMishra0307__ Жыл бұрын
Great Video Sir !! Also, for SQL Server, the best approach would be Row_Number(), that will solve both the problems.
@ankitbansal6
@ankitbansal6 Жыл бұрын
Yes, you are right
@souravsinha5330
@souravsinha5330 Жыл бұрын
Thanks a lot greatly explained...
@ankitbansal6
@ankitbansal6 Жыл бұрын
Glad it was helpful!
@khushishrivastava331
@khushishrivastava331 Жыл бұрын
Thank you for making such insightful videos on sql. Please advise some do's and don'ts in an interview or how to approach a problem statement.
@ankitbansal6
@ankitbansal6 Жыл бұрын
Noted
@shubhamgoyal3358
@shubhamgoyal3358 Жыл бұрын
@@ankitbansal6 Instead of giving links of so many videos try to give the code script
@Artouple
@Artouple Жыл бұрын
Great approach!
@ankitbansal6
@ankitbansal6 Жыл бұрын
Glad it was helpful!
@ankimedia5225
@ankimedia5225 7 ай бұрын
Please provide optimised query for to detect duplicates when we will having million rows and want query to run fast
@sudarsanrout5787
@sudarsanrout5787 11 ай бұрын
Great video sir❤
@ankitbansal6
@ankitbansal6 11 ай бұрын
Keep watching
@sarathmaya6083
@sarathmaya6083 Жыл бұрын
Nice explanation. May i know which IDE you are using?
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thank you. It's datagrip.
@sauravrajchaudhary9036
@sauravrajchaudhary9036 Жыл бұрын
Nice explnation
@ankitbansal6
@ankitbansal6 Жыл бұрын
Keep watching
@sandipjamdade4564
@sandipjamdade4564 Жыл бұрын
Thank You So So Much Ankit for putting in such great efforts....💯💯 But I have one Question How to delete pure duplicates without taking a backup of the table? Is It Possible?
@ankitbansal6
@ankitbansal6 Жыл бұрын
There is no standard way of doing it. Depending on databases it can be done.
@yuktibhatnagar9955
@yuktibhatnagar9955 7 ай бұрын
With cte as (Select*, row_number() over(partition by emp_id order by create_timestamp asc) as rank from employee a) Select emp_id, max(create_timestamp) From cte Group by emp_id;
@tusharshivhare9651
@tusharshivhare9651 Жыл бұрын
Hello sir, Can we use this approach also to remove multiple duplicates with cte as( select *, row_number() over(partition by emp_id order by timestamp desc) as rn from employee) delete from cte where rn>1
@mayankgupta7548
@mayankgupta7548 8 ай бұрын
No you deleting from cte Cte are views only
@akshayshirbhate7
@akshayshirbhate7 6 ай бұрын
Hey, what about if i have duplicate record but its id is different. In that case how would we delete that record?
@subhashdixit5167
@subhashdixit5167 Жыл бұрын
Please provide create table and insert statement like you used to provide in your odl videos
@ankitbansal6
@ankitbansal6 Жыл бұрын
There is nothing in the table. You can create table and data as per the video
@patilnaveenkumarreddy4059
@patilnaveenkumarreddy4059 Жыл бұрын
thankyou
@ankitbansal6
@ankitbansal6 Жыл бұрын
You're welcome!
@rahulgautam511
@rahulgautam511 Жыл бұрын
Ankit, your videos are just fabulous my friend. I am using SQL Server, While deleting duplicate records with multiple columns I am getting an error ("An expression of non-boolean type specified in a context where a condition is expected, near ','). Is it because that ,SQL Server doesn't support multiple column subqueries? Please confirm. Thanks in advance..
@ankitbansal6
@ankitbansal6 Жыл бұрын
Yes it doesn't support multiple columns. You can concatenate the 2 columns and then use in filter
@sahilummat8555
@sahilummat8555 Жыл бұрын
Hello Ankit Just wanted a little help . How is the course different from all the videos you have put . What additional knowledge will we get ?
@ankitbansal6
@ankitbansal6 Жыл бұрын
The course is in a structured manner covers from basic to advanced all the concepts along with assignments. Also covers 2 projects and premium subscriptions to practice SQL problems.
@sahilummat8555
@sahilummat8555 Жыл бұрын
@@ankitbansal6 when will the next batch start and is live batch any different from the recorded one you currently have on the website
@florincopaci6821
@florincopaci6821 Жыл бұрын
MERGE INTO your_table tgt USING ( SELECT ROWID AS rid, name, ROW_NUMBER() OVER ( PARTITION BY name ORDER BY ROWNUM ) As rn FROM your_table ) src ON (src.rid = tgt.ROWID AND src.rn > 1) WHEN MATCHED THEN UPDATE SET name = name DELETE WHERE 1 = 1; Unfortunatlly this will not work in Sql Server or at last me i couldn t make it work but in Oracle work like a charm. Happy Holydays.
@mbkamath3720
@mbkamath3720 Жыл бұрын
Mind blowing🤯🤯🤯..! Why using the alias A when you havnt used it anywhere like A.empid or A.salary?? This doubt follows me evrywhere..😓😔😔
@ankitbansal6
@ankitbansal6 Жыл бұрын
In SQL server it's mandatory to give aliases to a sub query.
@kundankumar5520
@kundankumar5520 Жыл бұрын
Hi Sir, thanks again for wonderful video, I tried deleting in workbench platform but it is not allowing me to delete. I have uncheck the safe mode as well. Error: You can't specify target table 'employee_new' for update in FROM clause. Same query I am using it: delete from employee_new where (emp_id, create_timestamp) = (select emp_id, min(create_timestamp) as create_timestamp from employee_new group by 1 having count(1) >1);
@zahoorahmadkareemi6267
@zahoorahmadkareemi6267 11 ай бұрын
same issue with me
@chennaivibes8428
@chennaivibes8428 Жыл бұрын
Hi can u provide the database you use so that it will be useful for practicing
@ankitbansal6
@ankitbansal6 Жыл бұрын
You can practice on any database. Just create the table and insert records
@mbkamath3720
@mbkamath3720 Жыл бұрын
Please give tips on not going blank during intrvws. The intrvwer acts hurry hurry and i end up saying 'i dont know' even though later i realise i knew the answer. So many opportunities missed due to this fear.😓😔😔😔
@rishav144
@rishav144 Жыл бұрын
Maybe u need to practice more questions before Interview ...For hurry , You can tell interviewer to give u 1 minute to think ... Ask him " May i think for a minute " and try to recall the answer in ur mind... and then answer accordingly ....This worked for me in 6-7 interviews of Data Analyst
@skillup638
@skillup638 Жыл бұрын
@@rishav144 hi rishav what are the Major skills required for data analyst and how to apply for companies ?
@LoveIndia3
@LoveIndia3 Жыл бұрын
i thought I am the only one who is facing this problem..i jumbled even after knowing the answers which make bad impression to interviewers which lead to rejection unnecessarily
@muralidhar9266
@muralidhar9266 8 ай бұрын
It's same with me also. knewing the right answer ,still can't recall at that moment, mind runs in hurry to impress or something else
@mohdmahtab8991
@mohdmahtab8991 Жыл бұрын
Please sir strat SQL courses from basic to Advance.
@ankitbansal6
@ankitbansal6 Жыл бұрын
Join here www.namastesql.com
@mohdmahtab8991
@mohdmahtab8991 Жыл бұрын
@@ankitbansal6 i checked it out but you don't list Normalization topic in your courses
@paragkelkar8538
@paragkelkar8538 Жыл бұрын
I am getting this error "An expression of non-boolean type specified in a context where a condition is expected, near ','." after running query delete from EMP2 where (Emp_id,create_date) in (select Emp_id, min(create_Date) as time_c from EMP2 group by Emp_ID having count(1)>1) Please comment what needs to be update in this
@ankitbansal6
@ankitbansal6 Жыл бұрын
Is it SQL server?
@paragkelkar8538
@paragkelkar8538 Жыл бұрын
@@ankitbansal6 Yes
@ankitbansal6
@ankitbansal6 Жыл бұрын
@@paragkelkar8538 ok so in SQL server you can not filter on 2 columns as tuple. Use this syntax using inner join DELETE w FROM WorkRecord2 w INNER JOIN Employee e ON EmployeeRun=EmployeeNo Do join on the 2 columns
@sreemalapal
@sreemalapal 3 ай бұрын
Hi..Can you share the name of the application you are using..This is not MS SQL Server
@ankitbansal6
@ankitbansal6 3 ай бұрын
Datagrip
@mohitupadhayay1439
@mohitupadhayay1439 Жыл бұрын
Not the best video in terms of video production but well explained a few things.
@ankitbansal6
@ankitbansal6 Жыл бұрын
Agree with you. Was trying a new IDE but it did not go well.
@reachrishav
@reachrishav Жыл бұрын
Please continue the tutorials in SSMS, this editor does not seem to go well
@ankitbansal6
@ankitbansal6 Жыл бұрын
Ok. Thanks for the feedback 😊
@chriskeo392
@chriskeo392 Жыл бұрын
Accent too heavy , thanks for content tho
@girdhar3224
@girdhar3224 Жыл бұрын
somewhat confusing...
@iamneeljadhav
@iamneeljadhav 8 ай бұрын
Good SQL problems but explanations not that good. Will love to watch if you speak in language you are comfartable to explain
1❤️
00:17
Nonomen ノノメン
Рет қаралды 12 МЛН
NERF WAR HEAVY: Drone Battle!
00:30
MacDannyGun
Рет қаралды 45 МЛН
ОДИН ДЕНЬ ИЗ ДЕТСТВА❤️ #shorts
00:59
BATEK_OFFICIAL
Рет қаралды 8 МЛН
DELETE DUPLICATE ROWS FROM A TABLE IN SQL || 4 ways
9:15
Crack Concepts
Рет қаралды 202 М.
Oracle PL SQL interview question | SQL to Delete duplicate records
17:27
Swiggy Data Analyst SQL Interview Question and Answer
17:05
Ankit Bansal
Рет қаралды 12 М.
Как слушать музыку с помощью чека?
0:36
Неразрушаемый смартфон
1:00
Status
Рет қаралды 2,3 МЛН
Игровой Комп с Авито за 4500р
1:00
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,9 МЛН