Reputation: 5
I am using the following query to get DISTINCT records I'm interested in.
SELECT DISTINCT
USERID, Policy_Name, Account_Type, WEEKNUM, EMPLOYEETYPE, MANAGERID
FROM table1
In table 1 there is also a column called Acc-Check.
I want to add Acc-Check to the results of the above query during or afterward without affecting the 'DISTINCT' number of results i.e. the output will then be:
USERID, Policy_Name, Account_Type, WEEKNUM, EMPLOYEETYPE, MANAGERID, Acc-Check
None of the columns are PK. Open to any suggestions and can edit the table as necessary.
USERID nvarchar(MAX)
Policy_Name nvarchar(MAX)
Account_Type nvarchar(MAX)
WEEKNUM nvarchar(MAX)
EMPLOYEETYPE nvarchar(MAX)
MANAGERID nvarchar(MAX)
Acc_Check nvarchar(MAX)
Upvotes: 0
Views: 99
Reputation: 44696
Do a GROUP BY
to get same result as before, add max("Acc-Check") to get one acc-check value.
SELECT
USERID, Policy_Name, Account_Type, WEEKNUM, EMPLOYEETYPE, MANAGERID, max("Acc-Check")
FROM table1
group by USERID, Policy_Name, Account_Type, WEEKNUM, EMPLOYEETYPE, MANAGERID
Upvotes: 1