How to find duplicates in a mariaDB tabel

Rinaldo 396 Reputation points
2024-01-06T21:48:31.98+00:00

Hi,

I have a database on the net and consist of 2 tabels i.e. Naam of the employee and his number.

number naam

1000 Rinaldo

1001 Other

how can i add a name and number without getting uplicates. I've found som on the net with google and is Linq what i do not get. Example in LINQ c# Please guide me to the process.

            var group = dt.AsEnumerable().GroupBy(row => row.Field<string>("Personeel")).Select(g => new
            {
                group = g.Key,
                first = g.Max(row => int.Parse(row.Field<string>("Naam"))).ToString(),
                second = g.Max(row => row.Field<int?>("PersoneelsNummer") ?? 0)
            }).ToList();


other I have tryed:

            var group = dt.AsEnumerable().GroupBy(row => row.Field<string>("Personeel")).Select(g => new
            {
                group = g.Key,
                first = g.Max(row => int.Parse(row.Field<string>("Naam"))).ToString(),
                second = g.Max(row => row.Field<int?>("PersoneelsNummer") ?? 0)
            }).ToList();

Al coming from StackOverflow

https://stackoverflow.com/questions/58835299/find-duplicates-in-a-datatable-then-compare-duplicates

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,487 questions
{count} votes

Accepted answer
  1. José Pablo Ramirez (a. k. a. webJose) 440 Reputation points
    2024-01-06T22:02:18.62+00:00

    You should create a unique index in the table to disallow the duplication:

    create unique index on myTable (number, naam);
    

    This way you cannot enter duplicates. Reference: CREATE INDEX

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.