jweissdandm
asked on
SQL SELECT DISTINCT with multuiple columns
I need to grab distinct email address and corresponding fName,lname from my table
I need something like this...
SELECT DISTINCT value1, value2 FROM table
Thanks
I need something like this...
SELECT DISTINCT value1, value2 FROM table
Thanks
SELECT DISTINCT emailaddress,
(SELECT TOP (1) fname
FROM table
WHERE (emailaddress= T.emailaddress)) AS FName,
(SELECT TOP (1) lname
FROM table
WHERE (emailaddress= T.emailaddress)) AS LName
FROM table AS T
GROUP BY emailaddress
(SELECT TOP (1) fname
FROM table
WHERE (emailaddress= T.emailaddress)) AS FName,
(SELECT TOP (1) lname
FROM table
WHERE (emailaddress= T.emailaddress)) AS LName
FROM table AS T
GROUP BY emailaddress
ASKER
would this work?
select value1,max(value2) as newColumn
from table1
group by value1
select value1,max(value2) as newColumn
from table1
group by value1
Yes. It would work with GROUP BY and AGGREGATE function as well.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for the explanation homie
from
(select emailaddress, fname, lname, rn = row_number() over( partition by emailaddress order by fname,lname ) from yourtable ) a where a.rn = 1