Home Answers Viewqa SQL Sql query Duplicate

 
 


Ashutosh Singh
Sql query Duplicate
2 Answer(s)      2 years and 6 months ago
Posted in : SQL

I have a Employee table with duplicate ID values. How can I find out duplicate records?

View Answers

December 18, 2010 at 4:10 PM


Hello Friend,

We have created a table named 'employee'.

CREATE TABLE `employee` (               
            `id` bigint(255) default NULL,        
            `name` varchar(255) default NULL,     
            `address` varchar(255) default NULL   
          )

In this table,we have entered following data:

1 A Delhi

1 B Mumbai

2 C Delhi

3 D Delhi

Then we have used the following query to find the duplicate data:

SELECT DISTINCT t1.id, t1.name,t1.address FROM employee t1, employee t2 WHERE t1.id= t2.id AND t1.name <> t2.name AND t1.address <> t2.address;

Hope that it will be helpful for you.

Thanks


December 18, 2010 at 5:19 PM


Hi,

Suppose you have following dataset:

CREATE TABLE `employee` (
  `id` bigint(255) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `employee` */

insert  into `employee`(`id`,`name`,`address`) values (1,'A1','A3');
insert  into `employee`(`id`,`name`,`address`) values (1,'A2','A3');
insert  into `employee`(`id`,`name`,`address`) values (1,'A3','A4');
insert  into `employee`(`id`,`name`,`address`) values (2,'B1','B2');
insert  into `employee`(`id`,`name`,`address`) values (2,'B1','B1');
insert  into `employee`(`id`,`name`,`address`) values (3,'D','D');

You can use following query to find the duplicate id:

select id, count(id) as cnt from employee group by id order by cnt desc;

Thanks Deepak Kumar









Related Pages:
Sql query Duplicate
Sql query Duplicate  I have a Employee table with duplicate ID values... 3 D Delhi Then we have used the following query to find the duplicate data...'); You can use following query to find the duplicate id: select id, count(id
SQL
SQL  Query to list out the duplicate rows in a table
Remove duplicate values
Remove duplicate values  i am trying to insert values into database from excel spreadsheet .am doing it using JDBC.connected both excel and sql...:publisher,dc:language in SQL database. in which dc:title will not allow null and dc:dcid
JDBC : Duplicate records in a table
. You can check this by writing  following  SQL query - sql...JDBC : Duplicate records in a table In this tutorial, you will learn how to find the duplicate records in a table. Duplicate records in a table : You
sql - SQL
2'nd least salary i want query? 3.how to find out duplicate rows in table i want query? 4.what is the diffrence between sql and plsql?  Hi Friend... employee); 3) The following query finds the duplicate rows from the table
avoid duplicate values using struts - Struts
of sql queryThis query returns a listthen your storing data is already...avoid duplicate values using struts  How to avoid the duplicate values in Struts?  IN action class you check before storeing itSee howFirst
Need to Remove Duplicate Records from Excel Sheet
empnum rating (without using sql query have to remove records from excel using java...Need to Remove Duplicate Records from Excel Sheet  Need to Remove Duplicate Records from Excel Sheet. I have one excel sheet having two fields
Sql Query
Sql Query  Is this query work in Db2 or not ? Select * from FORUM LIMIT 2
Sql Query
Sql Query  Is this query work in Db2 or not ? Select * from FORUM LIMIT 2
sql query
sql query  two tables are emp,loc write a query to display all the emp information whose locname not equal to bangalore
sql query
sql query  hi friend, Im doing a project,in that a main id... numbers of sids.i want to delete the sid based on the mid.for that i need sql query plz help to me
sql query
sql query  hi friend, Im doing a project,in that a main id... numbers of sids.i want to delete the sid based on the mid.for that i need sql query plz help to me
sql query
sql query  hi friend, Im doing a project,in that a main id... numbers of sids.i want to delete the sid based on the mid.for that i need sql query plz help to me
Sql Query
Sql Query  Hi M Navjeet Ghai I want to know How to Show A name(Like Navjeet Ghai And Manpreet Singh Sodhi) of employees from a employee table as N.Ghai & M.S.Sodhi by using sql query
SQL Query
SQL Query  Selecting the third highest salary of Employee without using any subquery?   Here is a query: SELECT salary FROM employee ORDER BY salary DESC LIMIT 2,1
SQL QUERY
SQL QUERY  am a having a table 'PROGRAMMER' with columns... C pascal Bhanu Sql... Pascal Sql Mahesh DBASE Cobol
sql query
sql query  SQL QUERY BROWSER declare @cout00 int declare @cout01 int declare @cout10 int declare @cout11 int declare @c1 float declare @gss float...); this is the query i have written for the table "dpscomp" - station date month
query - SQL
tell me how to write the query in database but not jsp code. thank u
java.sql.BatchUpdateException: Duplicate entry '135-16448' for key 1 - Hibernate
written ServerPreparedStatement.java:647 there is duplicate key in your Query... ServerPreparedStatement.java:647 there is duplicate key in your Query or it should be primary...java.sql.BatchUpdateException: Duplicate entry '135-16448' for key 1  
SQL query
SQL query  I need to combine two tables in order to get the values. As an example we have three tables having namely usertable,job table and jobaccess table. In usertable (Userid,Empid,name,Role) details have been stored
SQL Query - SQL
SQL Query  Hi I would like to know how to create a SQL query which would copy values from a field which contains multiple values to an existing... | +-----+-----------+-------------+ Query: INSERT INTO table2 (fruit1, fruit2, fruit3
sql query - SQL
sql query  hi sir,i have a month and year numbers,when i am enter a month and year in sql query then i want results for 1st day of month to last day of month in that year for that month plz provide a solution
sql query - JDBC
sql query  I need a SQL query to add data into database
optimize sql query
optimize sql query  How to optimize sql query in mysql? Thanks
SQL query - SQL
SQL query  hi sir/Madam i am using MS Access where i have table like Fees_Struc: Amount (INT) Due_Date (Date) Fees_Pay: Paid(INT) Student_Bal: Panalty(INT) my problem is when the Due_date is equal
SQL
; SQL - An Introduction to the Structured Query Language SQL stands for Structured Query Language (SQL), a standard language used for creating, updating, querying... or expressions. An asterisk can specify the query while SQL query can be made more
SQL Mode
;       mysql> SET sql_mode = ''; Query OK... SQL Mode       SQL... expression. When there are no duplicate values in the records, the mode returns NA
display sql query in hibernate
display sql query in hibernate  If you want to see the Hibernate generated SQL statements on console, what should we do
SQL QUERY - JDBC
SQL QUERY  I m running a query using apache tomcat the sql query is on adding an employee in the database whenever i click on add after inserting the values i am getting a java.lang.nullpointer exception
Hibernate SQL Query/Native Query
This tutorial describes Hibernate SQL Query, which is also known as Native Query
Sql query from oracle
Sql query from oracle  Please help me that I want to get the table names form the existing database who does it having eid coloumn plz provide me query in oracle database
Mysql Find Duplicate Records
| +-------+----------+--------+------------+ Query for finding duplicate records: The Query is used... Mysql Find Duplicate Records       Mysql Find Duplicate Records is used to find the duplicate Records
Named ? SQL query in hibernate
Named ? SQL query in hibernate  What is Named SQL query in hibernate... putting the sql queries to various places in between code. sample.hbm.xml <...;/property> </class> <query name="getProductByCode">
sql query search function
sql query search function  i have a textbox on a form , i like a search a data in the form, when i give whatever name and id or etc..its will search and show the same form , so help me using jsp
SQL QUERY ERROR
SQL QUERY ERROR  Im writing a query which shows error of INVALID CHARACTER The Query is Insert into PMST_EMP_MST(PMSNUM_EMP_ID,PMSSTR_EMP... THE FORM IS THROWING THE ERROR OF INVALID CHARACTER BUT THE SAME QUERY IS RUNNING
Doubt In Sql query
Doubt In Sql query  Hi Have a glance @ http://img98.imageshack.us/img98/4348/tableo.png For a single country there may be n numbers of country... tries with this query but it is returning redundancy records. select * from
SQL Query - JSP-Servlet
SQL Query   AS mysql backend updation query shows a syntax error. I gave the full query and the generated error here. Please send me the correct query anyone. st.executeUpdate("update stud_detail set name='"+newname
SQL date query
SQL date query  how to get ( 15 march 2011) and (15/03/2011) output using SQL   Use the following queries to get the data from database in the given format. For (15 march 2011) format: SELECT DATE_FORMAT(dob, '%d %M
Sql Join Query
Sql Join Query  aTable Name : TblState Stid StateName CountryId --------------------------------------------- 01 TN 01 02 KR 01 03 KL 01 04 WB 01 05 New
search query - SQL
. i have to search? how to do query for this? any one can help me
Hibernate Native SQL Query Introduction
In this section, you will learn Hibernate Native SQL query
SQL
SQL  hii What is sql?   hello, SQL, which stands for Structured Query Language, is a special-purpose language used to define, access, and manipulate data. SQL is non procedural, meaning that it describes
JDBC- SQL spatio-temporal query
JDBC- SQL spatio-temporal query  Any one give me a JDBC sql query... as shown in above. I want a spatio-temporal query using JDBC-SQL to retrieve... query2 7 trajectory is HHBHC I want a SQL query
JDBC- SQL spatio-temporal query
JDBC- SQL spatio-temporal query  Any one give me a JDBC sql query... as shown in above. I want a spatio-temporal query using JDBC-SQL to retrieve... query2 7 trajectory is HHBHC I want a SQL query
SQL display date in between query
SQL display date in between query  how to get ( 15 march 2011) and (15/03/2011) output using SQL
SQL
SQL   1)How to Store 1000 records in Oracle object. 2)Write a query for calculate highest, 3rd Highest & 10th highest salary from emp teble. 3)What is Sequence. 4)How to use rowid in Sql. 5)What is Views. 6)How
SQL
SQL  I have 2 queries.I want to run one query in the first day of month and i want to run other query in the other days of month for a routine.How to do
sql
sql  write a query to select emplname from employees where lname of employees should be equal
SQL
SQL  How do you increase performance of a query? Using batch, pagination, increasing JVM memory size
sql
sql  i need a query for selecting values from a table till a certain date...my database has date in the format '01-JAN-01 12.00.00.000000000 AM