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
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.
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.
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.
SELECT DataId, COUNT(*) c FROM DataTab GROUP BY DataId HAVING c > 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With