Step3 - Execute DELETE query DELETE FROM employee_details WHERE emp_id NOT IN (SELECT MAX(emp_id)įROM employee_details GROUP BY emp_id, emp_name, designation, manager_id,īy executing above query, we can delete the duplicate rows from employee_details table. Step2 – Verify the above query as a subquery to get duplicate rows SELECT * FROM employee_details WHERE emp_id NOT IN (SELECT MAX(emp_id)įROM employee_details GROUP BY emp_name, designation, manager_id,īy executing above query, we can get only duplicate rows from employee_details table. Note :- The columns in the GROUP BY are the columns having the duplicate values. SELECT MAX(emp_id) FROM employee_details GROUP BY emp_name,ĭesignation, manager_id, date_of_hire, salary, dept_id īy executing above query, we can get the DISTINCT rows emp_id from employee_details table. So prepare the query to get the latest unique rows emp_id from the table. In the above example, emp_id has unique values. Step1 – Prepare query to get only unique rows. Let us consider the above employee_details table with duplicates. Verify the query as a subquery to get duplicate rows.The process should follow the below steps – Let us see how to prepare the DELETE query. The temp_edetails table now contains the below rows -Įxecute DELETE query to delete the duplicate rows. INSERT INTO temp_edetailsīy executing above query, we can copy unique rows from employee_detail table to temp_edetails table. In your query, you can join two tables by the director’s ID to get a list of movies made by currently living directors: SELECT movies.title, directors.fullname. Depending on how the data is distributed, also consider doing an initial check for one value before checking if the other is also a duplicate. Step2 – Copy distinct rows from base table to temp table. CREATE TABLE temp_edetails ASīy executing above query, we can create temp_edetails table with the same structure as employee_details table. Step1 – Create table as employee_details.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |