how to mark duplicates value in table view?
-
- Veteran Member
- Posts: 32
- Joined: 2021-06-12 21:01
how to mark duplicates value in table view?
how to mark duplicates or more than 2 times repeating value in table view for certain field, and filter it as same values ?
Re: how to mark duplicates value in table view?
For avoiding duplicates you should set unique-flag.zkarwinkar wrote: ↑2022-02-01 05:25how to mark duplicates or more than 2 times repeating value in table view for certain field, and filter it as same values ?
Anyway, if there is duplicate data already in your database table, personally, I would create an additional field
is_duplicate
on that table, then do the checks on serverside (SQL+PHP) and update that new field if you detect a duplicate. Having this additional field and having records tagged as "duplicates", in the second step there are many ways for filtering, sorting, searching and highlighting.Given a table named
customers
having a column named email
, this is the SQL command for finding all duplicate emails:Code: Select all
SELECT `email`
FROM `customers`
WHERE `email` IS NOT NULL
group by `email`
having count(*)>1
is_duplicate
= 1 (and all the others = 0).(2) As an alternative, turn
is_duplicate
into a calculated field which automatically updates it's status.This is the SQL command* for the calculated field in the given example
* this is an example for good readability. There are more efficient ways in SQL. Subselects are not very performant but easy to use and understand here.
Code: Select all
SELECT
(SELECT count(*)>0 FROM customers WHERE A.email = email AND A.id != id)
FROM `customers` as A
WHERE A.id='%ID%'
Personally I prefer (1) over (2) because I'm very flexible when doing this for example in TABLENAME_init hook. There I can change my SQL conditions and update records according to my business requirements without changing and re-generating the project. But this is only my personal strategy. Especially I can re-evaluate all records and not only the displayed records. Calculated fields only work on displayed records unless you trigger the re-calculation manually.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 25.10 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 25.10 + all AppGini Helper tools
-
- Veteran Member
- Posts: 32
- Joined: 2021-06-12 21:01
Re: how to mark duplicates value in table view?
Thank you sir , it worked !!!
And yes i would also go for 1 instead of this , but i had requirement of matching and finding duplicates .
And yes i would also go for 1 instead of this , but i had requirement of matching and finding duplicates .