AutomaticSlim
asked on
Query returns duplicates
I have the following query that returns duplicates, I know If I add Distinct it wont.
Is there any other way to do this, this started to happen when I joind 2 more tables to my Query:
SELECT *
FROM AOS_PROVIDER_CONTRACT_EZCA P AS A
INNER JOIN AOS_PROVIDER_CLASSCODE_REF ON
A.CLASS = AOS_PROVIDER_CLASSCODE_REF .EZCAP_CLA SS_CODE
INNER JOIN AOS_PROVIDER_CONTRACT_REF_ TABLE ON
A.[EZCAP.PROV_MASTERS.PROV ID] = AOS_PROVIDER_CONTRACT_REF_ TABLE.[EZC AP.PROV_MA STERS.PROV ID]
LEFT JOIN ProviderContracts_BACKUP
ON ProviderContracts_BACKUP.P RVNO = A.[EZCAP.PROV_MASTERS.PROV ID]
Where ProviderContracts_BACKUP.P RVNO IS NULL
AND ProviderContracts_BACKUP.G RPID IS NULL
Is there any other way to do this, this started to happen when I joind 2 more tables to my Query:
SELECT *
FROM AOS_PROVIDER_CONTRACT_EZCA
INNER JOIN AOS_PROVIDER_CLASSCODE_REF
A.CLASS = AOS_PROVIDER_CLASSCODE_REF
INNER JOIN AOS_PROVIDER_CONTRACT_REF_
A.[EZCAP.PROV_MASTERS.PROV
LEFT JOIN ProviderContracts_BACKUP
ON ProviderContracts_BACKUP.P
Where ProviderContracts_BACKUP.P
AND ProviderContracts_BACKUP.G
Yes. Post the Table Structure. or any result set .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
select * from four tables will return a huge composite row as a concatenation of data in each and every joined table
I'm sure you don't need all this stuff
Adding a 'distinct ' in the select will not change anything, because the values from joined tables will always be different (unless they have duplicate rows)
To decrease the number of rows, you have to define what you need first
Select distinct A.* will return less rows
also I think the end of the query
LEFT JOIN ProviderContracts_BACKUP
ON ProviderContracts_BACKUP.P RVNO = A.[EZCAP.PROV_MASTERS.PROV ID]
Where ProviderContracts_BACKUP.P RVNO IS NULL
AND ProviderContracts_BACKUP.G RPID IS NULL
could be replaced by
where not exists (select 'x' from ProviderContracts_BACKUP where ProviderContracts_BACKUP.P RVNO = A.[EZCAP.PROV_MASTERS.PROV ID])
HTH
Hilaire
I'm sure you don't need all this stuff
Adding a 'distinct ' in the select will not change anything, because the values from joined tables will always be different (unless they have duplicate rows)
To decrease the number of rows, you have to define what you need first
Select distinct A.* will return less rows
also I think the end of the query
LEFT JOIN ProviderContracts_BACKUP
ON ProviderContracts_BACKUP.P
Where ProviderContracts_BACKUP.P
AND ProviderContracts_BACKUP.G
could be replaced by
where not exists (select 'x' from ProviderContracts_BACKUP where ProviderContracts_BACKUP.P
HTH
Hilaire
please explain the relation ships between the tables..?
what are you trying to show?