-
SELECT DISTINCT on 2 columns
with SELECT DISTINCT a,b,c,d FROM x i get distinct abcd value
how can I do SELECT DISTINCT a,b,c,d FROM x but only distinct on a,b (no matter if c,d are equals or differents) ?
I am using MS SQL 2000 and Accees 2000
thank you
-
Post example data and result you want.
You can't do partial distinct in a SELECT, you can group by a, b and get max or min of c and d
select a,b,min(c), min(d)
from x
group by a, b
-
if I have
1, a1, b1
2, a1, b1
3, a1, b2
i want to get
1, a1, b1
3, a1, b2
let's say the first one found (no matter which one)
thank you
-
create table t1(id int, col1 varchar(3),col2 varchar(3))
insert into t1 select 1, 'a1', 'b1'
insert into t1 select 2, 'a1', 'b1'
insert into t1 select 3, 'a1', 'b2'
select min(id) as ID,col1,col2 from t1
group by col1,col2
-
it works very well , thanks a lot !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|