1. Christian Breu
  2. Valentina Studio
  3. Sonntag, Februar 19 2017, 01:19 PM
  4.  Abonnieren via E-Mail
What is the best way to select records with no duplicates in one table?
I need to get the RecID of a record where it could have duplicates related to columns A, B and C.

Anything like this does not work.
Is there a way or what is the best way to do that?


SELECT RecID FROM (Select A, B, C FROM tableX GROUP BY A, B, C);
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
Hi Christian,

Each group of duplicates has set of RecIDs delimited by comma:

SELECT * FROM
( SELECT COUNT(*) AS cnt, GROUP_CONCAT( RecID ) FROM tableX GROUP BY A, B, C )
WHERE cnt > 1


Is that what you need?
Kommentar
There are no comments made yet.
Christian Breu Akzeptierte Antwort
Hello Sergey

I have 100'000 records containing some duplicates.
Duplicates are defined by equal values in columns A, B, C and actually D.
The Value of column RecID of course is different.
I can use DISTINCT or GROUP BY to get only one of the duplicated records.

I am looking for a solution to fix this problem by either delete the duplicates or select only the one of the duplicated records.
Deleting is always bad so I was thinking to select only one of the records.
My problem is, to select DISTINCT I have to check columns A, B, C, D but in the result I need column RecID.
(Kernel error: 0x42508. In the SELECT clause you can use only fields listed in the GROUP BY and aggregative functions)
Is this possible? How?
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
Hi Christian,

That is possible, but do you need to run it regularly?
Or just once?

That's how it works for me - select only the first RecID in group.

SELECT FIRST( RecID ) FROM tableX GROUP BY A, B, C;
Kommentar
There are no comments made yet.
Christian Breu Akzeptierte Antwort
Hello Sergey

Thank you, looks good.
I thought to run this regularly.
Is this a problem?
To get a specific record the query needs 9 ms on a mac mini testserver.
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
No problem.
I thought it can be slow on a large dataset.
Kommentar
There are no comments made yet.
Christian Breu Akzeptierte Antwort
That is great – Thank you again!
Kommentar
There are no comments made yet.
  • Seite :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Categories

Announcements & News
  1. 0 subcategories
Valentina Studio
  1. 2 subcategories
Valentina Server
  1. 4 subcategories
Valentina Database ADK
  1. 0 subcategories
Valentina Reports ADK
  1. 0 subcategories
Other Discussions
  1. 2 subcategories
BETA Testing
  1. 0 subcategories
Education & Research
  1. 0 subcategories