Hello,
I would like to prevent Contacts being inserted into the database when inserted Contact:
firstname + ', ' + lastname + ', ' + workphone
is identical with existing Contacts:
firstname + ', ' + lastname + ', ' + workphone
Can this be done with an Insert Trigger and if so, how? Thank you in advance,
LarsYou could add an alternate key to the entity on those attributes. In your physical implementation, add a "UNIQUE" constraint and a unique index on those columns. It could be done with a trigger, but it will probably not preform as well.|||I'll second that recommendation. A UNIQUE constraint should be more efficient (and simpler) than any trigger you could write.
-PatPsql
Showing posts with label firstname. Show all posts
Showing posts with label firstname. Show all posts
Tuesday, March 27, 2012
Monday, March 26, 2012
duplicate record
Dear All,
I need to identify duplicate records in a table. TableA [ id, firstname, surname] Id like to see records that may be duplicates, meaning both firstname and surname are the same and would like to know how many times they appear in the table
Im not sure how to write this query, can someone help? Thanks in advance!try something like this:
select id, fname, lastname, count(*)
from tablename
having count(*) > 1|||Use a subquery with the HAVING clause to isolate duplicated firstname/lastname records, then link to the table to get id values:
select YourTable.id,
YourTable.firstname,
YourTable.surname,
YourSubquery.occurances
from YourTable
inner join --YourSubquery
(select firstname,
surname,
count(*) as Occurances
from YourTable
group by firstname,
surname
having count(*) > 1) YourSubquery
on YourTable.firstname = YourSubquery.firstname
and YourTable.surname = YourSubquery.surname|||try something like this:
select id, fname, lastname, count(*)
from tablename
having count(*) > 1
Hmm ok, doesn't look complex at all, thanks!
It gave me error messages about not having a grouped by statement in there, so I added it. It works fine, thanks a lot!sql
I need to identify duplicate records in a table. TableA [ id, firstname, surname] Id like to see records that may be duplicates, meaning both firstname and surname are the same and would like to know how many times they appear in the table
Im not sure how to write this query, can someone help? Thanks in advance!try something like this:
select id, fname, lastname, count(*)
from tablename
having count(*) > 1|||Use a subquery with the HAVING clause to isolate duplicated firstname/lastname records, then link to the table to get id values:
select YourTable.id,
YourTable.firstname,
YourTable.surname,
YourSubquery.occurances
from YourTable
inner join --YourSubquery
(select firstname,
surname,
count(*) as Occurances
from YourTable
group by firstname,
surname
having count(*) > 1) YourSubquery
on YourTable.firstname = YourSubquery.firstname
and YourTable.surname = YourSubquery.surname|||try something like this:
select id, fname, lastname, count(*)
from tablename
having count(*) > 1
Hmm ok, doesn't look complex at all, thanks!
It gave me error messages about not having a grouped by statement in there, so I added it. It works fine, thanks a lot!sql
Subscribe to:
Posts (Atom)