select a.id,a.name from table1 a where a.rowid=(select min(b.rowid) from table2 b where a.id=b.id)
select * from table1 a where rowid=(select min(rowid) from table1 where id=a.id)
select a.id , frist_value( a.name ) from table1 a group by a.id
min函数不是单行函数,不能用where. select a.id , a.name from table1 a group by a.id having a.rowid=1
select distinct id,min(name) from table1 group by id order by id;
首先,我建立的表跟斑竹的表几乎是一样的,方法也是一样的。 SQL> select * 2 from tbtry 3 / ID NAME ---------- ---------- 1 a 1 b 2 c 2 d 3 a 4 s 5 y 5 f 方法一 SQL> select a.id,a.name 2 from tbtry a,(select min(rowid) minrowid 3 from tbtry 4 group by id) b 5 where a.rowid in b.minrowid 6 / ID NAME ---------- ---------- 1 a 2 c 3 a 4 s 5 y 方法二 SQL> select id,name 2 from tbtry 3 where rowid in (select min(rowid) 4 from tbtry 5 group by id) 6 / ID NAME ---------- ---------- 1 a 2 c 3 a 4 s 5 y
select id,min(name)
from table1
group by id
order by id
赤赤 赤赤.
table2 b where a.id=b.id)
where rowid=(select min(rowid) from table1 where id=a.id)
select a.id , a.name from table1 a
group by a.id
having a.rowid=1
SQL> select *
2 from tbtry
3 / ID NAME
---------- ----------
1 a
1 b
2 c
2 d
3 a
4 s
5 y
5 f
方法一
SQL> select a.id,a.name
2 from tbtry a,(select min(rowid) minrowid
3 from tbtry
4 group by id) b
5 where a.rowid in b.minrowid
6 / ID NAME
---------- ----------
1 a
2 c
3 a
4 s
5 y
方法二
SQL> select id,name
2 from tbtry
3 where rowid in (select min(rowid)
4 from tbtry
5 group by id)
6 / ID NAME
---------- ----------
1 a
2 c
3 a
4 s
5 y