Тёмный

How to delete duplicate records from a table in SQL | How to delete duplicate rows in SQL 

ItJunction4all
Подписаться 12 тыс.
Просмотров 107 тыс.
50% 1

How to delete duplicate records from a table in SQL | Multiple ways to delete duplicate records in SQL
In this video, multiple ways has been shown to delete duplicate records from a table.
1. By using GROUP BY clause and MAX()
2. By using CTE and ROW_NUMBER()
Follow me on Social Networking Sites :
*Twitter:
/ sunilkr5672
*Instagram :
/ itjunction4all
Input Script :
Create Table EmpDetail (
ID int identity(1,1),
EmpName varchar(25),
Departmemt varchar(20),
Age int,
Gender char(1),
Salary Bigint
)
Insert into EmpDetail values('James','HR',30,'M',40000)
Insert into EmpDetail values('James','HR',30,'M',40000)
Insert into EmpDetail values('James','HR',30,'M',40000)
Insert into EmpDetail values('John','Finance',32,'M',45000)
Insert into EmpDetail values('Maria','Admin',28,'M',30000)
Insert into EmpDetail values('Maria','Admin',28,'M',30000)
Insert into EmpDetail values('Mark','Account',35,'M',50000)
#SQLInterviewQuestionsandanswers #sqlInterviewQuestions #sqlInterviewQuestionsForTesting #sqlInterviewQuestionsQuery #sqlInterviewQuestionsOnJoins #sqlTechnicalInterviewQuestions #SQLforETLTesters #CommonSqlInterviewQuestions #ETLTesting
#DeleteDuplicateRecordsFromTable #ITJunction4All

Наука

Опубликовано:

 

13 июл 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 88   
@yonashabtesllassie5642
@yonashabtesllassie5642 3 года назад
Very good explanation, very clear and cleaver way.... Thank you it helped me a lot
@ItJunction4all
@ItJunction4all 3 года назад
You are welcome! Thank you for such a nice feedback !
@SamuelLed2k24
@SamuelLed2k24 11 месяцев назад
thank you! been working on the same problem for a while now, and I have finally solved it because of this video.
@ItJunction4all
@ItJunction4all 11 месяцев назад
You are welcome! I am glad that my video helped you.
@tonygiovanni5761
@tonygiovanni5761 2 месяца назад
Good stuff. I like the way you make easy. Brief and straight to the point. Keep posting more videos
@ItJunction4all
@ItJunction4all 2 месяца назад
Thanks a lot Tony ! Please subscribe my channel so that you will get all my future videos updates
@rajeshSharma-od4sn
@rajeshSharma-od4sn Год назад
Nicely explained by you sir Very helpful video Thank you sir
@ItJunction4all
@ItJunction4all Год назад
Thanks Rajesh ! I hope you will like my other videos as well.
@masheTyMasha
@masheTyMasha Год назад
Thank you so much! Very loligicall explained.
@ItJunction4all
@ItJunction4all Год назад
You're very welcome!
@rohitdeshbhratar6467
@rohitdeshbhratar6467 3 года назад
Hi, i am executing with clause query in Oracle PLSQL developer and i am getting error missing select keyword. Please help me.
@sumancreative2806
@sumancreative2806 Год назад
Nice explanation.. Thank You...
@ItJunction4all
@ItJunction4all Год назад
You are welcome Suman !
@akpaneno9643
@akpaneno9643 5 месяцев назад
This was really helpful.
@ItJunction4all
@ItJunction4all 5 месяцев назад
You are welcome 😍😍
@mohamednawfel5172
@mohamednawfel5172 3 года назад
this is really helpful
@ItJunction4all
@ItJunction4all 3 года назад
Thank you !
@dhruvchaudhary_7
@dhruvchaudhary_7 5 месяцев назад
What if we use distinct function? Our output would be the same or not?
@mdaquib7836
@mdaquib7836 2 года назад
Thanks for your help. 2nd option Helped
@ItJunction4all
@ItJunction4all 2 года назад
You're welcome Aqib !
@familybannas8809
@familybannas8809 Год назад
Love ur explanations
@ItJunction4all
@ItJunction4all 11 месяцев назад
Thanks a lot 😊
@rohandevaki4349
@rohandevaki4349 Год назад
great explaination
@ItJunction4all
@ItJunction4all Год назад
Thanks a lot Rohan Devaki ! 😍 😍
@MrSayandeep
@MrSayandeep 3 года назад
Thanks a lot
@ItJunction4all
@ItJunction4all 3 года назад
Most welcome Sayandeep !
@jagannathgaidhani5333
@jagannathgaidhani5333 2 года назад
sir, which platform are you using for this. i am using CLI its very difficult there to execute big Query.
@ItJunction4all
@ItJunction4all 2 года назад
I am using SQL Server.
@lokeshhousnoor3099
@lokeshhousnoor3099 Год назад
Thanks Alot
@ItJunction4all
@ItJunction4all Год назад
You're welcome Lokesh ! I hope you are liking my other SQL videos as well. Let me know your feedback ?
@chidinganyadi6796
@chidinganyadi6796 11 месяцев назад
Thank you Sir. I have a question. What if the column names are many, will we start typing all of them in
@ItJunction4all
@ItJunction4all 11 месяцев назад
Yes, you will have to type all column names.
@hannahgetachew8909
@hannahgetachew8909 2 года назад
thank you
@ItJunction4all
@ItJunction4all 2 года назад
You're welcome Hannah Getachew !
@thebestken
@thebestken 2 года назад
What if the unique id is not integer but a unique identifier like Guid? You can’t use max there. How will you do it?
@ItJunction4all
@ItJunction4all 2 года назад
Thanks for writing Ken Singh ! Max function works on alphanumeric values as well . I think it will work on Guid as well.
@galazostephaniemae1919
@galazostephaniemae1919 3 года назад
Sir how about in windows 10?
@push_freebird6693
@push_freebird6693 Год назад
fabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb finally got a solution!!!!!!! thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ItJunction4all
@ItJunction4all Год назад
You are welcome ! I hope you will like other videos of my channel as well !
@prasadkumbhar1656
@prasadkumbhar1656 3 года назад
Sir I have a doubt, Suppose with the same table if there is no ID column but there are some other column as well say (deptno,deptname,loc, etc)which have duplicate records and the table does not have primary key column defined in this case how should we delete duplicate records where there are more no of columns??
@ItJunction4all
@ItJunction4all 3 года назад
Hi Kumbhar...In that scenario, you can delete duplicate data by the way i have explained using CTE and Row_Number(). I hope this will help.
@debashisahu
@debashisahu 3 года назад
@@ItJunction4all sir there also you have used order by id , so how to tackle that one
@SanketBandi
@SanketBandi Год назад
@@ItJunction4all SIR it is not taking Row_Number() as key word what should i do?
@ItJunction4all
@ItJunction4all Год назад
@@SanketBandi Which database are you using ?
@Sharmine_
@Sharmine_ 2 года назад
Thanks for the video. I am trying to use CTE and ROW_NUMBER(), however I got this error: The target table tableName_CTE of the DELETE is not updatable. Do you know how to resolve the error?
@ItJunction4all
@ItJunction4all 2 года назад
Thank you Sharmine for writing ! Could you please tell me which database you are using ?
@Sharmine_
@Sharmine_ 2 года назад
@@ItJunction4all I am using mySQL workbench
@ItJunction4all
@ItJunction4all 2 года назад
Looks like delete from a CTE on MySQL 8+ is not working. It works good in Sql Server database. You can go for another approach for deleting duplicate records in mySQL database.
@Sharmine_
@Sharmine_ 2 года назад
@@ItJunction4all I also tried the first DELETE method, the problem is it took a long time and will only display timeout
@ItJunction4all
@ItJunction4all 2 года назад
@@Sharmine_ Ohh..I see. How many duplicates you are trying to delete from your table ?
@VeronicaAngryPolak
@VeronicaAngryPolak Год назад
could you write a case statement for duplicate rows and delete duplicates that way?
@ItJunction4all
@ItJunction4all Год назад
I don't think it is possible to delete duplicate records using case statement
@Basireddy-li5mq
@Basireddy-li5mq Месяц назад
Hi Sir, post we run these query still showing duplicate records in table------ delete from frds where frd_id not in ( select max(frd_id) from frds group by frd_name,dob,salary,dept_id);
@prashantsingh1892
@prashantsingh1892 2 года назад
Sir using first method if i have different id name and rest of the records are same then it will not fetch as a duplicate values, So your first method is only for if the duplicate values are same if anything row number value is different it will not
@ItJunction4all
@ItJunction4all 2 года назад
Thanks for writing Prashant ! First query will work if you have unique id for each row. Let me know if this clarifies your doubt .
@prashantsingh1892
@prashantsingh1892 2 года назад
@@ItJunction4all got it sir.. Thankyou 😇
@ItJunction4all
@ItJunction4all 2 года назад
@@prashantsingh1892 Welcome Prashant !
@user-vf2dk8eg4g
@user-vf2dk8eg4g 10 месяцев назад
I Don't understand, why did you use Duplicate_CTE . Could you please explain.
@chittibabu8149
@chittibabu8149 6 месяцев назад
Same
@user-id9yf2vm8v
@user-id9yf2vm8v 9 месяцев назад
If this query will run in mysqlworkbench 8.0 in Mac laptop because its not running in my laptop..please help
@ItJunction4all
@ItJunction4all 9 месяцев назад
I think MySQL 8.0 supports these SQL queries
@leecallaghan4625
@leecallaghan4625 8 месяцев назад
good day . i have an issue with my leads platform . when i enter a lead it says it already exists . i wa looking into this issue and found that it maybe an issue with a DUPLICATE KEY . does anyone have any idea .
@malisachin469
@malisachin469 5 месяцев назад
it's showing "ERROR 1288: The target table duplicate_CTE of the UPDATE is not updatable" in MYSQL. plz help me with this
@hemaprajapati8866
@hemaprajapati8866 5 месяцев назад
I am facing this same problem
@behindthescenesreality9368
@behindthescenesreality9368 3 года назад
Sir before making video please maintain visible screen size it's hardly visible to me may be it's only my problem or for other also don't know...
@ItJunction4all
@ItJunction4all 3 года назад
Ok Sure. Thanks !
@shambhum1829
@shambhum1829 2 года назад
Sir great information but video is not proper visible screen size very small please can you make this same video one more time and upload
@nandhini24586
@nandhini24586 6 месяцев назад
@ItJunction4all
@ItJunction4all 6 месяцев назад
Thanks
@uma1910
@uma1910 3 года назад
Are you continuing these questions?
@ItJunction4all
@ItJunction4all 3 года назад
Yes I will continue adding questions as and when time permits me.
@MAH-ls1if
@MAH-ls1if 9 месяцев назад
what is CTE?
@ItJunction4all
@ItJunction4all 9 месяцев назад
CTE is Common Table Expression
@manmathan0762
@manmathan0762 2 года назад
Your method is not working for me bro is shows error: releation "duplicate_cte does not exist Line 6: Delete from Duplicate_CTE where Dupont >1
@ItJunction4all
@ItJunction4all 2 года назад
Which database are you working ?
@manmathan0762
@manmathan0762 2 года назад
Postgres bro I was new pls guide me
@manishmishra6245
@manishmishra6245 Год назад
8:21 using cte
@ItJunction4all
@ItJunction4all Год назад
Thanks Manish Sharma !
@vishnuvamshi4645
@vishnuvamshi4645 2 года назад
NOT WRITTEN QUERY IN DESCRIPTION PLEASE ADD THE QUERY
@ItJunction4all
@ItJunction4all 2 года назад
Vishnu..All queries are there in video.
@rizwanwaheed3073
@rizwanwaheed3073 Год назад
Thank you
@ItJunction4all
@ItJunction4all Год назад
You're welcome Rizwan !
@chittibabu8149
@chittibabu8149 6 месяцев назад
What is duplicate cte
@ItJunction4all
@ItJunction4all 6 месяцев назад
CTE is a Common Table Expression. With the help of CTE , duplicate record was deleted
@RijyoMagazine
@RijyoMagazine 8 месяцев назад
Video not clear
@ItJunction4all
@ItJunction4all 8 месяцев назад
Video is clear...open this video from RU-vid and go to settings and then click on Quality and select 1080pixel quality. Your video clarity will be equivalent to HD video
Далее
I Built 100 Homes And Gave Them Away!
09:36
Просмотров 45 млн
ШАР СКВОЗЬ БУТЫЛКУ (СКЕРЕТ)
00:46
DELETE DUPLICATE ROWS FROM A TABLE IN SQL || 4 ways
9:15
SQL Remove Duplicate Rows: A How-To Guide
4:46
Просмотров 38 тыс.
Part 4   Delete duplicate rows in sql
3:26
Просмотров 737 тыс.
Don't Drag it In Excel | Use these tricks
2:28
Просмотров 53 тыс.
Телефон в воде 🤯
0:28
Просмотров 1,2 млн