Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SELECT UNIQUE DATA

Author  Topic 

R@bb1t
Starting Member

28 Posts

Posted - 2008-01-18 : 02:21:47
Hi, I would like to know how can you select unique firstname, lastname from a table... that is eliminating duplicate rows. distinct does not work... please help

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-18 : 03:03:36
Do you get any errors using DISTINCT?

Please provide some proper sample data and your expected output.
Also post information why you think DISTINCT do not work.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

R@bb1t
Starting Member

28 Posts

Posted - 2008-01-18 : 03:34:31
The select statement is as follows:

SELECT FirstName, LastName FROM Members_Profile
UNION
SELECT FirstName, LastName FROM Newsletter

How can I eliminate duplicate rows...

Yes, distinct cannot work here!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-18 : 03:45:47
by duplicate, do you mean the combination of firstname and lastname should be different?
As said, post some sample data with expected result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-01-18 : 03:50:45
If I have got your problem correctly you are trying some things sort of given below:
create table #Name
(
firstname varchar(30),
lastname varchar(30)
)

GO

create table #News
(
firstname varchar(30),
lastname varchar(30)
)
GO


insert into #Name values ('vishal','sharma')
insert into #Name values ('Varun','singh')
insert into #Name values ('sunil','kumar')


insert into #News values ('vishal','sharma')
insert into #News values ('Varun','singh')
insert into #News values ('sunil','kumar')
insert into #News values ('pankaj','jain')
insert into #News values ('neeraj','anand')


select firstname,lastname from #Name
Union
select firstname,lastname from #News

It is not giving duplicate result.
Go to Top of Page
   

- Advertisement -