• RPSql (6/18/2013)


    Is there a way to structure a single query to select all the unique values from field 1 of table A, and the unique values from field 2 of Table A and then select count(*) for all of the resulting combinations of field 1 and field 2 values?

    Thanks in advance.

    maybe something like this?

    the UNION will merge duplicates between the two tables.

    SELECT

    COUNT(Columnname) As TotalCount

    FROM (

    SELECT DISTINCT ColumnName FROM Table1

    UNION

    SELECT DISTINCT OtherColumnName FROM Table2

    )MyAlias

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!