Skip to Content
avatar image
Former Member

Union three queries to show all results

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 03, 2015 at 09:45 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 03, 2015 at 10:46 AM

    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

    Add comment
    10|10000 characters needed characters exceeded