SELECT A.* FROM 表 A JOIN
(
SELECT MIN(字段1) AS 字段1,字段2 FROM 表 GROUP BY 字段2
) B ON (A.字段1=B.字段1 AND A.字段2=B.字段2)
ORDER BY A.字段1
没有测试,想着就写了,你试一下吧
select
distinct
name
from
a
where
eid
in(select
eid
from
b
group
by
eid)
要求查询在b表出现过的企业名称,不重复
这样就够了.至于根据时间倒叙
和结果没影响.
Select distinct 字段1,字段2 from 表名 order by 字段1
保证正确,我刚刚试过了,使用distinct(不重复)后order by 的字段也必须出现在Select之中
create table tb
(
ID int,
VALUE varchar(10)
)
insert into tb(ID,VALUE) values(1,'A')
insert into tb(ID,VALUE) values(2,'A')
insert into tb(ID,VALUE) values(3,'B')
insert into tb(ID,VALUE) values(4,'B')
insert into tb(ID,VALUE) values(5,'C' )
insert into tb(ID,VALUE) values(6,'D' )
select VALUE from tb where [ID] in(
select min([ID]) from tb group by VALUE
) order by [ID]
drop table tb
select 字段2 from 表 order by 字段1 asc 或者 desc
asc 是正序 desc 是倒序 估计你的错误就是没加