cancel
Showing results for 
Search instead for 
Did you mean: 

Union three queries to show all results

Former Member
0 Kudos

Hi

I have three queries that i'd like to package into one so that each result is displayed in a separate column. Any help would be much appreciated.

Separate queries are below

SELECT count (distinct T0.[CardCode])[MMS Professional Customers] FROM OCRD T0 WHERE T0.[QryGroup17] ='y'  and T0.[validFor] ='y'

SELECT count (distinct T0.[CardCode])[MMS Community Customers] FROM OCRD T0 WHERE T0.[QryGroup15] ='y'  and T0.[validFor] ='y'

SELECT count (distinct T0.[CardCode])[MMS Professional Customers] FROM OCRD T0 WHERE T0.[QryGroup17] ='y'  and T0.[validFor] ='y'

Cheers

Lisa

Accepted Solutions (1)

Accepted Solutions (1)

Johan_H
Active Contributor
0 Kudos

Hi Lisa,

Please try this:

SELECT (SELECT count (distinct T0.[CardCode])[MMS Professional Customers] FROM OCRD T0 WHERE T0.[QryGroup17] ='y'  and T0.[validFor] ='y') AS Column1

,(SELECT count (distinct T0.[CardCode])[MMS Community Customers] FROM OCRD T0 WHERE T0.[QryGroup15] ='y'  and T0.[validFor] ='y') AS Column2

,(SELECT count (distinct T0.[CardCode])[MMS Professional Customers] FROM OCRD T0 WHERE T0.[QryGroup17] ='y'  and T0.[validFor] ='y') AS Column3

Of course you can rename the columns to something a little more descriptive.

Regards,

Johan

Former Member
0 Kudos

Thanks so much Johan, worked a treat!

Answers (1)

Answers (1)

Former Member
0 Kudos

HI

This query should work

select (SELECT count(T0.[CardCode]) FROM OCRD T0 WHERE T0.[QryGroup17] ='y'  and T0.[validFor] ='y') as MMSProfessionalCustomers


SELECT count (distinct T0.[CardCode]) FROM OCRD T0 WHERE T0.[QryGroup15] ='y'  and T0.[validFor] ='y' ) as MMSCommunityCustomers


SELECT count (distinct T0.[CardCode]) FROM OCRD T0 WHERE T0.[QryGroup17] ='y'  and T0.[validFor] ='y') as MMSProfessionalCustomers

shachar

Former Member
0 Kudos

Thanks Saado, appreciate the help