Amanda Walshaw
asked on
view results showing duplicates
Hello I have written a view which has to show two diffrent display flags and if the hierarchy on this view is a rate flag
i have created 3 union statements, whilst I am getting all the results in my test database I am missing a condition. to stop the duplicate results based on the two display flags. view is attached.
union-view.txt
i have created 3 union statements, whilst I am getting all the results in my test database I am missing a condition. to stop the duplicate results based on the two display flags. view is attached.
union-view.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ahh now the light has gone on I will try this.
ASKER
but what about the fields I have to null out. that is why I needed the union when the case type is true I need to NULL out all the fields but it needs to be displayed.
When Displayflag2 is 1 only I need to null out the contact details.
only when you have this condition
displayflag1 =1 and displayflag2 =1 or displayflag1 = 1 and displayflag2 = 0
can I show everything... contact role is related to displayflag1.
When Displayflag2 is 1 only I need to null out the contact details.
only when you have this condition
displayflag1 =1 and displayflag2 =1 or displayflag1 = 1 and displayflag2 = 0
can I show everything... contact role is related to displayflag1.
ASKER
sorry correction the rateflag is the hierarchy flag not the case type.
Is this for a report? What is the reporting tool?
anyway, try the combine query please
ASKER
Appolgies its been a long day, here is the corrected view I cannot send the real data but thread is the same, the third union I have to null out the fields when display2 is selected as you don't want to see the customer contact details as well I have corrected the date fields.
union-view.txt
union-view.txt
Do you understand the difference between UNION and UNION ALL?
You have 4 subqueries, each have identical FROM clauses.
There are differences in the SELECT clauses
and whilst there are 4 different WHERE clauses 3 of them are quite similar
However, due to the differences introduced to the rows with the selection lists - you will not achieve the desired "simplification" using UNION
just a tiny difference in rows is considered unique by UNION (or DISTINCT)
I believe you are trying to replicate or produce a "report" - SQL is not a report writer.
I cannot "picture" what you are trying to do exactly - what are your "expected results"
Q-28161257.xlsx
You have 4 subqueries, each have identical FROM clauses.
There are differences in the SELECT clauses
and whilst there are 4 different WHERE clauses 3 of them are quite similar
However, due to the differences introduced to the rows with the selection lists - you will not achieve the desired "simplification" using UNION
just a tiny difference in rows is considered unique by UNION (or DISTINCT)
I believe you are trying to replicate or produce a "report" - SQL is not a report writer.
I cannot "picture" what you are trying to do exactly - what are your "expected results"
Q-28161257.xlsx
ASKER
I will come back to you on this I was asked to combine two views into one, I had disagreed as I knew I would come across this issue of duplication.
they are extract scripts from sql to be displayed on websites.
but I am using dummy data to on exchange to explain the problem.
I cannot use company data, but I will consult with a sql developer and see what they say.
thanks
they are extract scripts from sql to be displayed on websites.
but I am using dummy data to on exchange to explain the problem.
I cannot use company data, but I will consult with a sql developer and see what they say.
thanks
you should not expect SQL to do this form of manipulation - it should be performed within the programmic logic layer - all you will end-up with is a quite a mess
truly - this is not a good idea in SQL
does the site use PHP? .Net? - it can (and should) be done there
- this manipulation of data for presentation is NOT an sql task
truly - this is not a good idea in SQL
does the site use PHP? .Net? - it can (and should) be done there
- this manipulation of data for presentation is NOT an sql task
Open in new window
I have not tried to simplify further. Please indicate if this helps with this issue as it is - before trying for simplification.