July 18, 2005 at 9:13 pm
Hi friends
i need ur advise on this query.I've 2 fields in a table (patient,invoice).
field invoice contains invoice no for a patient.this no can be duplicated for the same patient but not for the different patient.
i mean we can have data like this
patient invoice
pk patient invoice
1 John I001
2 John I001
3 Paul I002
but there should not be like following
pk patient invoice
1 John I001
2 John I001
3 Paul I001 --its wrong
4 Paul I002
my question is how can i find out such duplicates ?
Thanks
July 18, 2005 at 10:12 pm
something like this?
select distinct a.patient, a.invoice, b.patient, b.invoice
from table a
, table b
where a.patient <> b.patient
and a.invoice = b.invoice
and a.pk < b.pk
order by a.invoice
July 19, 2005 at 12:10 am
July 19, 2005 at 12:33 am
It shouldn't make any difference as long as pk is unique I think!!
did it work??
July 19, 2005 at 7:37 am
select distinct a.patient, a.invoice, b.patient, b.invoice
from table a
, table b
where a.patient <> b.patient -- Make sure this can not be null
and a.invoice = b.invoice
and a.pk <> b.pk -- Minor change
order by a.invoice
* Noel
July 19, 2005 at 4:51 pm
and a.pk <> b.pk -- Minor change
This won't work, it does not return unique duplicates.
July 19, 2005 at 5:01 pm
Thank u very much Journeyman and Noel .
finally i got it sorted it in following way
SELECT patient, invoice FROM Patients PInvoiceWHERE PInvoice.Invoice IN
(SELECT Invoice FROM Patients PDup WHERE PDup.Patient # PInvoice.Patient)
GROUP BY PInvoice.patient, PInvoice.invoice
By the way Journeyman am running this query (i did not mention before) on
visual foxpro data and ur query hangs my PC for some reason but abv query is fine!!
Anyway i really appreciate ur help and it gave different way of looking at problem
and find solution.Thanks
July 19, 2005 at 5:28 pm
As you can see I never work with foxpro before
cheers
July 20, 2005 at 5:59 pm
Try this,
Select Patient,invoice count(*)
From TablepateientInvoice
Group by Patient,invoice
Having count(*) > 1
July 20, 2005 at 6:10 pm
Thanks suresh.
ur query also worked nicely.in this case it also returns records which are not duplicated across patients.
what i mean ,say i've 10 records with same invoice no "I1" for same patient and no other patient has this no still abv query returns that invoice no in result.
anyway thats for ur time.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply