How to delete duplicate records from MySQL table | MySQL query to delete duplicate records

Many of the interviews I was asked a common MySQL question and the questions was, Write a MySQL query to delete the duplicated records from MySQL table.
Here in this small article I'll be explaining MySQL query to get duplicate records and to delete the duplicate records.

For example you have a users table and inside the users table we have duplicate email id of user so the first question how to get the duplicate records ?
Here is the MySQL query to get the duplicate records:

It will return duplicate emails along with the count of duplicate emails.



Now we wanted to delete the duplicate records. Here are some scenarios, either you wanted to keep the highest record or you wanted to keep the lowest record. ...  Read More

Share This:


How many columns we can update in single MySQL query and What is maximum length of column name, table name and database name?

  • We can update maximum 64 columns in a single MySQL query.
  • A column name of MySQL table can be upto 64 characters.
  • A MySQL table name can be of 64 characters.
  • A MySQL database name can be of maximum 64 characters.

Share This:


Second Highest Salary without subquery in MySQL | Nth highest Salary without subquery | MySQL second highest salary query

In so many interviews Interviewer will ask you a very simple MySQL query. And the question is :

How to select 2nd,3rd or the Nth highest salary from a table in MySQL ?

If you will answer with sub query like below query:

Next question might be asked like:

How to select 2nd,3rd or the Nth highest salary from a table in MySQL without using sub query ?

To get the second highest salary of an employee here is the MySQL query:

If you wanted to get 3rd highest salary then here is below MySQL query to get the 3rd highest salary:

If you wanted to get nth highest salary then here is below MySQL query to get the nth highest salary:

for example if you wanted to write MySQL query to get 4th highest salary of the employee then the query will be like:

  ...  Read More

Share This: