No video

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

  Рет қаралды 25,696

Ankit Bansal

Ankit Bansal

Күн бұрын

Пікірлер: 68
@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 5 ай бұрын
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!
@addhyasumitra90
@addhyasumitra90 Ай бұрын
create table employee ( emp_id int, emp_name varchar(20), salary int, create_timestamp time); INsert into employee values (1, 'Ankit', 20000, GETDATE()), (2, 'Rahul', 20000, GETDATE()), (3, 'Agam', 30000, GETDATE()), (1, 'Ankit', 15000, GETDATE())
@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!
@sarathmaya6083
@sarathmaya6083 Жыл бұрын
Nice explanation. May i know which IDE you are using?
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thank you. It's datagrip.
@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 9 ай бұрын
No you deleting from cte Cte are views only
@sudarsanrout5787
@sudarsanrout5787 Жыл бұрын
Great video sir❤
@ankitbansal6
@ankitbansal6 Жыл бұрын
Keep watching
@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.
@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.
@yuktibhatnagar9955
@yuktibhatnagar9955 8 ай бұрын
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;
@ankimedia5225
@ankimedia5225 9 ай бұрын
Please provide optimised query for to detect duplicates when we will having million rows and want query to run fast
@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
@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 10 ай бұрын
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
@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.
@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
@patilnaveenkumarreddy4059
@patilnaveenkumarreddy4059 Жыл бұрын
thankyou
@ankitbansal6
@ankitbansal6 Жыл бұрын
You're welcome!
@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
@akshayshirbhate7
@akshayshirbhate7 8 ай бұрын
Hey, what about if i have duplicate record but its id is different. In that case how would we delete that record?
@rajat1999gupta
@rajat1999gupta 7 күн бұрын
Hello Ankit, is there a way to delete pure duplicate record without taking backup of original table. Please help me with this. Thanks in advance.
@ankitbansal6
@ankitbansal6 7 күн бұрын
Which database ?
@rajat1999gupta
@rajat1999gupta 7 күн бұрын
@@ankitbansal6 for MySql
@rajat1999gupta
@rajat1999gupta 6 күн бұрын
@@ankitbansal6 for MySQL
@sreemalapal
@sreemalapal 5 ай бұрын
Hi..Can you share the name of the application you are using..This is not MS SQL Server
@ankitbansal6
@ankitbansal6 5 ай бұрын
Datagrip
@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
@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 Жыл бұрын
same issue with me
@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
@reachrishav
@reachrishav Жыл бұрын
Please continue the tutorials in SSMS, this editor does not seem to go well
@ankitbansal6
@ankitbansal6 Жыл бұрын
Ok. Thanks for the feedback 😊
@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.
@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
@chriskeo392
@chriskeo392 Жыл бұрын
Accent too heavy , thanks for content tho
@girdhar3224
@girdhar3224 Жыл бұрын
somewhat confusing...
@iamneeljadhav
@iamneeljadhav 10 ай бұрын
Good SQL problems but explanations not that good. Will love to watch if you speak in language you are comfartable to explain
All About SQL Aggregations | SQL Advance | Zero to Hero
17:43
Ankit Bansal
Рет қаралды 52 М.
SPONGEBOB POWER-UPS IN BRAWL STARS!!!
08:35
Brawl Stars
Рет қаралды 21 МЛН
КАКУЮ ДВЕРЬ ВЫБРАТЬ? 😂 #Shorts
00:45
НУБАСТЕР
Рет қаралды 3,4 МЛН
WHO CAN RUN FASTER?
00:23
Zhong
Рет қаралды 46 МЛН
How to Crack Data Engineering Interviews
20:41
Ankit Bansal
Рет қаралды 11 М.
The BEEFY mini PC - Minisforum AtomMan G7 PT
12:40
ShortCircuit
Рет қаралды 132 М.
DELETE DUPLICATE ROWS FROM A TABLE IN SQL || 4 ways
9:15
Crack Concepts
Рет қаралды 203 М.
Oracle PL SQL interview question | SQL to Delete duplicate records
17:27
Data Engineering Free Resources (SQL, Spark, Data Modelling)
17:54