DELETE DUPLICATE ROWS FROM A TABLE IN SQL || 4 ways

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.พ. 2025

ความคิดเห็น • 183

  • @crackconcepts
    @crackconcepts  ปีที่แล้ว

    ✨Link to my SQL e-book: imojo.in/rkajq9
    ✨Link to 'Switch your career easily' e-book: imojo.in/1FL7KaG
    (Perfect for anyone willing to switch to a completely new field or to a different company in the Tech World)

  • @rajkiranboggala9722
    @rajkiranboggala9722 4 ปีที่แล้ว +35

    I really appreciate your time and effort in sharing these (even though you are having cold)!! Thank you

    • @srinivasprasad7765
      @srinivasprasad7765 3 ปีที่แล้ว

      Ya true..👍

    • @ravindrabisht7372
      @ravindrabisht7372 3 ปีที่แล้ว +1

      That's called dedication...keep it up dear

    • @ShubhamKumar-mf4sg
      @ShubhamKumar-mf4sg 2 ปีที่แล้ว

      Having cold ..hahaha..nailed it bro

    • @tubepankajyou
      @tubepankajyou 2 ปีที่แล้ว +1

      Such developers actually reach to top positions, appreciate it.

  • @karthikd2104
    @karthikd2104 4 ปีที่แล้ว +6

    Seen so many videos in SQL messed up ...this one really understandable with clear explanation!

  • @adapass
    @adapass 3 ปีที่แล้ว +1

    explanation is very clear by writing in paper which is unique in youtube. great job

  • @tchelaa6894
    @tchelaa6894 ปีที่แล้ว +1

    I have been stuck on this since yesterday. Thank you😎

  • @marvinmachitar7229
    @marvinmachitar7229 3 ปีที่แล้ว +1

    Wow! You are so good teacher. Was able to understand it more than other videos with fancy animation.

  • @umaannamalai3205
    @umaannamalai3205 4 ปีที่แล้ว +5

    Thank you for the clear explanations! You made the concepts simple to understand. I’m excited for new videos.

  • @MoodyVideoGraphies
    @MoodyVideoGraphies 2 ปีที่แล้ว

    kitni awesome hai yaar... So well explained... calm and soothing...

  • @rakeshgopidi4066
    @rakeshgopidi4066 3 ปีที่แล้ว +10

    It's a great post Sadia, no matter how many years of experience we have ,it's always a good revision for any one
    # Additional Reference
    There are also other ways to restrict the duplicates
    1. UNIQUE
    2. UNION
    3. ROW_NUMBER | RANK () | DENSE_RANK () - Analytical Function
    4. INTERSECT
    5. MINUS
    6. ROWID | ROWID + CORRELATED SUBQUERY
    7. GROUP BY

  • @mastanshaik5479
    @mastanshaik5479 3 ปีที่แล้ว +1

    Nice & simple way of understanding 👏👏 for new starters in sql ur videos are best .. thank you for ur efforts and time

  • @akashagarwal6390
    @akashagarwal6390 4 ปีที่แล้ว +9

    Mam it would be great if you can take up topics or concepts which are really important like this though not much frequently asked in interviews and also it is useful for an engineer to know all these as well

  • @husler7424
    @husler7424 2 ปีที่แล้ว

    Watching in 2022, for placements as being CSE student. Thanks a lot, didi. Your explanation is just amazing.

  • @giridandi7480
    @giridandi7480 2 ปีที่แล้ว

    Very nice.simple understanding way you explain so nice

  • @rajendrarajendra583
    @rajendrarajendra583 2 ปีที่แล้ว

    Your explanation is superb. one small request what ever you explained can you explain in sql server . that is very use full to us.

  • @sushantpawar5635
    @sushantpawar5635 3 ปีที่แล้ว

    शेंबडाचा त्रास होत असताना देखील खूप छान शिकवलंस🙏👍 thank you

  • @hidden590
    @hidden590 4 ปีที่แล้ว +4

    First method is easy to understand ...so I will go with the first method

    • @FitVisionTV
      @FitVisionTV 3 ปีที่แล้ว

      First method will overload database performance. Avoid using select *

  • @naveenshagala3136
    @naveenshagala3136 5 ปีที่แล้ว +1

    Nice explanation with such a calm voice.

  • @bhavanikandikondamatam5926
    @bhavanikandikondamatam5926 3 ปีที่แล้ว +6

    Hello madam..
    I have doubt in using temporary table..
    Can insert distinct values in new table
    Drop the old table
    Rename new table as old table?

  • @saravananbhojan8750
    @saravananbhojan8750 3 ปีที่แล้ว

    Learned best way to query thanks for the video !!

  • @rajattalnikar6167
    @rajattalnikar6167 3 ปีที่แล้ว

    Thankyou so much. You've covered all the methods and discussed them in detail.

  • @Rjjithin777
    @Rjjithin777 3 ปีที่แล้ว

    Simply superb, doing a great job, simple and clear

  • @maryamfatima5882
    @maryamfatima5882 2 ปีที่แล้ว

    excellent explanation

  • @ankiturmaliya7286
    @ankiturmaliya7286 ปีที่แล้ว

    very good explanation..

  • @akashverma1640
    @akashverma1640 3 ปีที่แล้ว +1

    Thank you very much for you efforts... Must to be known things👌👌

  • @zafariqbalunknown9786
    @zafariqbalunknown9786 2 ปีที่แล้ว

    Your efforts helped me a lot Thankyou mam

  • @deepakaggarwal8624
    @deepakaggarwal8624 3 ปีที่แล้ว

    Excellent, your solutions are just great and easy to understand

  • @ganeshstars1
    @ganeshstars1 3 ปีที่แล้ว

    your explanation is good. I am watching most of the videios.
    for me 1 st method is showing error missing expression.

  • @boddanapalliavinash6418
    @boddanapalliavinash6418 2 ปีที่แล้ว

    Very good explanation keep it up 👍

  • @veerulinganagoudar3456
    @veerulinganagoudar3456 2 ปีที่แล้ว

    It's really helpful

  • @DeepakMeena-kz9bu
    @DeepakMeena-kz9bu 4 ปีที่แล้ว

    over partition example was really helpful

  • @oic_Oracle_integration_cloud
    @oic_Oracle_integration_cloud 2 ปีที่แล้ว

    SO SIMPLE AND EASY

  • @swapneelkambe2092
    @swapneelkambe2092 2 ปีที่แล้ว

    Good explanation

  • @umeshgolla2730
    @umeshgolla2730 5 ปีที่แล้ว +2

    Excellent explaination..

  • @MUSKAN0896
    @MUSKAN0896 2 ปีที่แล้ว

    This was very helpful! Thank you so much

  • @aeriesx4727
    @aeriesx4727 3 ปีที่แล้ว

    Absolutely brilliant explanation... Thank you so much..

  • @hadireg
    @hadireg 3 ปีที่แล้ว +1

    a bit speedy but you're doing a great job!

  • @joshyjohn9636
    @joshyjohn9636 3 ปีที่แล้ว

    Well explained, It will be most useful video in this topic..

  • @azharuddinluhar9667
    @azharuddinluhar9667 3 ปีที่แล้ว +1

    3rd and 4th way will delete duplicate row from result set and not from actual table, now what to do for deleting duplicate rows from actual actual?

  • @techninja9461
    @techninja9461 3 ปีที่แล้ว

    Excellent Explanation.....This video is really helpful.

  • @tushardeepsingh4976
    @tushardeepsingh4976 4 ปีที่แล้ว

    Hii.. Please clear one question in this video ..In CTE inner query ..you have not used * after select keyword ..you have directly written " select row_number()..." .... * aaega na after select ??

  • @mohansaivelagapudi929
    @mohansaivelagapudi929 2 ปีที่แล้ว

    Thanks for Helping

  • @meditationandrelaxationmus741
    @meditationandrelaxationmus741 3 ปีที่แล้ว

    Thanks it is very important interview question

  • @nimmikcherian3242
    @nimmikcherian3242 4 ปีที่แล้ว

    Very detailed description... thanks

  • @nausheen292
    @nausheen292 3 ปีที่แล้ว

    Very well explained....Thank you 😀

  • @rosonerri-faithful
    @rosonerri-faithful 2 ปีที่แล้ว

    Can we use the MAX(ID) method?

  • @shwetabudake6144
    @shwetabudake6144 3 ปีที่แล้ว

    Very well explained

  • @leesubiramaniyam2704
    @leesubiramaniyam2704 3 ปีที่แล้ว

    Explaining good & may be increase the volume (sound) better good

  • @mudasar8629
    @mudasar8629 4 ปีที่แล้ว +1

    Thank a lots !!! :) Hope to see more videos from you.

  • @Sriramlivz
    @Sriramlivz 4 ปีที่แล้ว

    Nice Explaination. You have a lovely voice

  • @namratanikam7566
    @namratanikam7566 3 ปีที่แล้ว

    Well explained👍

  • @shivyogi806
    @shivyogi806 5 ปีที่แล้ว

    You have amazing, simple.way of teaching.
    God bless you
    and
    Thank you very much

  • @dreambig1668
    @dreambig1668 4 ปีที่แล้ว

    Hi just one suggestion you first way will always not would the solution for routine. N in your second way we have to design table with identify type then you will be able to access

  • @ravindrabisht7372
    @ravindrabisht7372 3 ปีที่แล้ว

    Your English is good

  • @richardconnolly4295
    @richardconnolly4295 3 ปีที่แล้ว

    SUPER HELPFUL!

  • @Aryan-ly5ho
    @Aryan-ly5ho 4 ปีที่แล้ว

    Helped me a lot Thanks 😁

  • @mannu567
    @mannu567 ปีที่แล้ว

    Instead of MIN if we use Max then what will happen? I guess it will also remove duplicate

  • @jaganjayakumar4874
    @jaganjayakumar4874 5 ปีที่แล้ว

    Clear explanation keep doing more videos👍

  • @mrf7283
    @mrf7283 4 ปีที่แล้ว +5

    very good effort and I appreciate your clips. However I have a question; suppose application messed up and gave same ID to two (2) different unique valid name. eg. 5001 to ABC and 5001 to XYZ and we want to keep both that is they should exists in our resultant with 2 unique IDs. Please don't get me wrong I am not trying to trick you, I had this real situation once with thousands of rows and was stuck.

    • @MohanGonnabathula
      @MohanGonnabathula ปีที่แล้ว

      In that scenario, you need to add ID, name in partition.
      DELETE FROM (
      SELECT *, ROW_NUMBER() OVER (PARTITION BY ID, NAME ORDER BY ID) AS Rno
      FROM emp
      ) AS E
      WHERE Rno > 1;
      This query will delete duplicate rows from the "emp" table where duplicates are determined by the combination of "ID" and "NAME" columns, keeping only the first occurrence and removing the rest.

  • @maxiejane
    @maxiejane 4 ปีที่แล้ว +1

    So helpful thank you for sharing!

  • @sohailkat8867
    @sohailkat8867 3 ปีที่แล้ว +1

    Nice video, and it would be great if you could make a video on types of Analytical Functions in sql, thanks!

  • @shubhamchoudhary5461
    @shubhamchoudhary5461 4 ปีที่แล้ว

    So informative...👍

  • @praveenvadde278
    @praveenvadde278 3 ปีที่แล้ว

    Good explanation. Can please explain and show by executing in the system.

  • @ravaliannaldas9320
    @ravaliannaldas9320 2 ปีที่แล้ว

    Nyc video sister.

  • @YPTechDATIA
    @YPTechDATIA 4 ปีที่แล้ว

    use insert into newtable select distinct * from oldtable; then delete * from oldtable; now insert into oldtable select * from newtable;

  • @akash_pal
    @akash_pal 4 ปีที่แล้ว +1

    well Explained !! Thank you.

    • @bro_7079
      @bro_7079 4 ปีที่แล้ว

      th-cam.com/video/zA9v9lnP2BE/w-d-xo.html

  • @shankar8816
    @shankar8816 3 ปีที่แล้ว

    Ek different positive way me le gye aap lecture ko.. Wldone

  • @AmanKhan-ei4cg
    @AmanKhan-ei4cg 4 ปีที่แล้ว +1

    Thanks for such stuff🥰

  • @foolchandsonariwal4203
    @foolchandsonariwal4203 2 ปีที่แล้ว

    Madam derived table delete allow nahi karta he only u can use cte to delete duplicate record.

  • @shubhamanand1347
    @shubhamanand1347 5 ปีที่แล้ว

    your videos are awesome please make more videos on different topics

  • @saisumanthnagasuri7741
    @saisumanthnagasuri7741 2 ปีที่แล้ว

    What happen if there are more than 50 columns with the duplicate records
    Instead of passing all the columns names to the partition by clause
    Is there any way to put * .
    Any thoughts?

  • @labheshlalka9666
    @labheshlalka9666 3 ปีที่แล้ว +1

    Why we can't use direct delete query whose count greater than 1

  • @mangamanasvi5485
    @mangamanasvi5485 4 ปีที่แล้ว +1

    Good Job!, Thank you.

  • @saurabhbenbanshi3460
    @saurabhbenbanshi3460 4 ปีที่แล้ว

    thanks you explained well...

  • @arjunpawar4564
    @arjunpawar4564 4 ปีที่แล้ว

    In third method : Can we access alias rn in outer query as well as use in where condition ?

  • @vivekrahate2564
    @vivekrahate2564 2 ปีที่แล้ว

    Thank u dear..

  • @vrcks8066
    @vrcks8066 3 ปีที่แล้ว

    ur voice is so nice😍

  • @antojeanston4781
    @antojeanston4781 5 ปีที่แล้ว

    it will be really helpful , if you do this on your system, please,
    it should be a live workout from your end, instead of explaining it on the written paper.

    • @priyakumar3802
      @priyakumar3802 5 ปีที่แล้ว

      She will explain the way she wants to explain.You should be thanking her instead of showing flaws

  • @CarlosRivera-mp7mm
    @CarlosRivera-mp7mm 2 ปีที่แล้ว

    Excelente muchas gracias

  • @aditiarjun519
    @aditiarjun519 6 หลายเดือนก่อน

    Hello mam, deleting using CTE throws the following error.... "Error Code: 1288. The target table cte of the DELETE is not updatable" how to resolve it?

  • @tushardeepsingh4976
    @tushardeepsingh4976 4 ปีที่แล้ว

    Hi..one question i have ..pls rply ASAP... I'm using MYSQL and MYSQL doesn't support select * into.. therefore i used insert into newtable select distinct * from old table ...here i faced one issue...i hv one tble with eid,ename and salary. eid field is PK and ename and salary has duplicate values ...now when i use insert into using distinct keyword it copies duplicate data as well ......i only want distict data to be copied ..i tried dropping PK but on column eid but i'm facing same issue

  • @yes-pg5dy
    @yes-pg5dy 4 ปีที่แล้ว

    Excellent madam pls do videos on power bi also pls

  • @alekhyabodapati5003
    @alekhyabodapati5003 3 ปีที่แล้ว

    where rn>1 is not a good practice use having rn> 1 instead of it. Good video

  • @88pianissimo90
    @88pianissimo90 2 ปีที่แล้ว

    I think row_number( ) works slower ... right? If you have millions of records then this will work slow.

  • @sukritsen9530
    @sukritsen9530 5 ปีที่แล้ว +2

    Hello, I have a question, how to delete duplicate records with no unique key in mysql? Can this be done using the row_number function?

    • @chanduch8973
      @chanduch8973 4 ปีที่แล้ว +4

      DELETE K FROM
      (SELECT *, ROW_NUMBER () OVER (PARTITION BY emp_id ORDER BY emp_id) AS RN FROM MyTable) K
      WHERE RN>1

  • @kshathrugan5238
    @kshathrugan5238 5 ปีที่แล้ว

    The first method ,the same query will it work in Oracle sql

  • @helmiboubaker2742
    @helmiboubaker2742 4 ปีที่แล้ว +1

    sorry but the third ways not working for me . this the query that i use
    delete from
    (select nom, row_number() over(partition by nom order by nom ) as count_num from fourniseurs)as tab where count_num >1;
    but the select query work fine i wander why is it not working i use workbench mysql :/

    • @mobileminimaster3015
      @mobileminimaster3015 3 ปีที่แล้ว

      delete from fourniseurs where nom IN (select nom from (select nom,row_number() over(partition by nom) as count_num from fourniseurs) ee where ee.count_num>1 );

  • @qaz_testzaq_test8138
    @qaz_testzaq_test8138 4 ปีที่แล้ว

    Good work, thanks

  • @norbycreation1851
    @norbycreation1851 2 ปีที่แล้ว +1

    INSERT INTO temp_table SELECT DISTINCT * FROM old_table;

  • @music4u1235
    @music4u1235 2 ปีที่แล้ว

    so sNice tutorialt like that

  • @preetidwivediatharv135
    @preetidwivediatharv135 5 ปีที่แล้ว

    Excellent explaination but Voice is little bit low.

  • @ishatawade
    @ishatawade 3 ปีที่แล้ว

    What is the difference between delete and truncate?

  • @dstar2211
    @dstar2211 5 ปีที่แล้ว

    superb...good job...

  • @rk-ej9ep
    @rk-ej9ep 3 ปีที่แล้ว

    Very nice

  • @digitalcode5685
    @digitalcode5685 2 ปีที่แล้ว

    THANKS

  • @shubhamshingi4657
    @shubhamshingi4657 3 ปีที่แล้ว

    Will 3rd and fourth approach delete row from original table or it will just delete from temp table/result sets ? can you please clear my doubt

    • @galymzhankenesbekov2924
      @galymzhankenesbekov2924 3 ปีที่แล้ว

      i also had the same doubt, but decided to insert into temporary table first and then do operations in a temporary table instread of original DB

    • @octotube463
      @octotube463 3 ปีที่แล้ว

      Both of them won’t impact the actual table. 4th method is just removing the duplicates from the temp table, you can achieve by using a distinct query 😂. My guess for the 3rd query is it will remove both the duplicate and the actual record.

  • @ammuachusmommy7352
    @ammuachusmommy7352 3 ปีที่แล้ว +1

    Please increase your sound.. Ur tone is low. But ur explanation is really good.

  • @mrrishiraj88
    @mrrishiraj88 3 ปีที่แล้ว

    Great videos.

  • @ramchinthakayala2092
    @ramchinthakayala2092 4 ปีที่แล้ว

    How come only distinct values will stored in new table if use -- Insert into old_table select * from new _table
    ? pls explain

    • @yashgoswami5374
      @yashgoswami5374 3 ปีที่แล้ว

      because than new table has distinct values

  • @HardikShah17
    @HardikShah17 4 ปีที่แล้ว

    Perfect. Thanks.

  • @sandysahu5651
    @sandysahu5651 3 ปีที่แล้ว

    The row_number() methodology is not working in snowflake db . anyone help me on this, how to resolve this like if we have to mention some alias name aslo and instead of rn>1 if we have to write alias.rn>1