Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find duplicate column value in sqlite

I have inserted some values in the table DataTab.

SomeId: Integer     => Autogenerated primary key. DataId: Guid DataNumber: Integer DataType: varchar 

The above are the column's in my tables, I want to find, if the table contains Repeated DataId values. It has been long time I had worked with databases. Now I can figure out simple queries. But I found this some what difficult.

I tried the following query, is this correct?

SELECT * from (Select * from DataTab) AS X  where DataId= X.DataId AND SomeId!=X.SomeId 
like image 737
51k Avatar asked Feb 24 '14 06:02

51k


People also ask

How can I get unique values from a column in SQLite?

Introduction to SQLite SELECT DISTINCT clause In this syntax: First, the DISTINCT clause must appear immediately after the SELECT keyword. Second, you place a column or a list of columns after the DISTINCT keyword. If you use one column, SQLite uses values in that column to evaluate the duplicate.

How do I select duplicate records in SQL?

To select duplicate values, you need to create groups of rows with the same values and then select the groups with counts greater than one. You can achieve that by using GROUP BY and a HAVING clause.

How do you find duplicate record in a table?

One way to find duplicate records from the table is the GROUP BY statement. The GROUP BY statement in SQL is used to arrange identical data into groups with the help of some functions. i.e if a particular column has the same values in different rows then it will arrange these rows in a group.


1 Answers

SELECT DataId, COUNT(*) c FROM DataTab GROUP BY DataId HAVING c > 1; 
like image 161
Jwalin Shah Avatar answered Oct 09 '22 04:10

Jwalin Shah