Home Forums Programming General SQL - How to group by on two fields and count RE: SQL - How to group by on two fields and count

  • How about:

    SELECT COUNT(*), X.[UserName]

    FROM

    (SELECT

    `user1` [UserName],

    FROM usuarios

    WHERE (`user1` is not null)

    UNION ALL

    SELECT

    `user2` [UserName],

    FROM usuarios

    WHERE (`user2` is not null)) X

    GROUP BY X.[UserName]

    ORDER BY X.[UserName]

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:
    http://www.sqlservercentral.com/articles/61537/