Question : UNION vs DISTINCT

Hi Experts,
I have a question regarding performance. I have a two tables that hold permissions for Groups.

tblA
------------
AID
PermissionTypeID
GroupID

tblB
-------------
BID
PermissionTypeID
GroupID

I would like to get all permissions from both tables into a single resultset. I can think of a different of ways of doing this.
1) Using UNION
SELECT     PermissionTypeID, GroupID
FROM         tblA
UNION
SELECT     PermissionTypeID, GroupID
FROM         tblB

2) Using DISTINCT
SELECT DISTINCT tblC.PermissionTypeID, tblC.GroupID FROM
(
SELECT     PermissionTypeID, GroupID
FROM         dbo.tblPermissionProduct
UNION ALL
SELECT     PermissionTypeID, GroupID
FROM         dbo.tblPermissionProductVersion
) As tblC

3) Using GROUP BY
SELECT PermissionTypeID, GroupID FROM
(
SELECT     PermissionTypeID, GroupID
FROM         dbo.tblPermissionProduct
UNION ALL
SELECT     PermissionTypeID, GroupID
FROM         dbo.tblPermissionProductVersion
)
GROUP BY PermissionTypeID, GroupID

Provided I do not want aggregates, just of list of unique entries of PermissionTypeID and GroupID, which method would perform best.

Thanks for your time.

Answer : UNION vs DISTINCT

Since the UNION already filters uniquely, it would be my choice.  Don't think you are gaining much performance wise, but from that standpoint, the UNION is the most simply query so why add overhead of derived queries to do DISTINCT or GROUP BY method you showed.  KISS principle.
Random Solutions  
 
programming4us programming4us