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 2000 Forums
 Transact-SQL (2000)
 How to distinct 2 fields in one statement?

Author  Topic 

eashoori
Starting Member

22 Posts

Posted - 2007-09-27 : 10:47:17
I want to select 2 different fields in a statment but I need both of them to return non recurring recoirds, how can I distinct both on the same statement?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-27 : 10:49:11
SELECT DISTINCT Col1, Col2
FROM Table1



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

eashoori
Starting Member

22 Posts

Posted - 2007-09-27 : 11:54:49
No I mean if I want single occujrance on both fields, meaning distinct on each field, the previous one distinct all the fields together, it gives me the distinct rows of all of them together
Go to Top of Page

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2007-09-27 : 12:25:22
Keep in mind that I'm guessing a bit as your requirements are incredibly vague

select distinct '' as col1, col2 from table1
union all
select distinct col1, '' as col2 from table1

Of course you provided no schema and no data to work with so I'm not sure what you're really looking for.

Hopefully this helps.
Go to Top of Page

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2007-09-27 : 12:29:57
Or if you want to be fancy


select A.Col1, B.Col2 from
(select distinct (Col1) from Table1) as A
full join
(select distinct (Col2) from Table1) B on 1=2

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-27 : 13:14:19
Do you have some proper and accurate sample data together with your expected result?



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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-28 : 02:50:24
quote:
Originally posted by eashoori

No I mean if I want single occujrance on both fields, meaning distinct on each field, the previous one distinct all the fields together, it gives me the distinct rows of all of them together


Did you mean Suppress if duplicated?
As asked, post some sample data with expected result

Madhivanan

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

- Advertisement -