当前位置:首页 » 编程语言 » sql语句查询除ID
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql语句查询除ID

发布时间: 2023-05-05 05:58:23

sql中如何查询出一个表中的所有的ID(仅ID 因为要用DELETE删除数据)

select id from 表名

Ⅱ SQL查询中如何剔除重复

1,存在两条完全相同的纪录

这是最简单的一种情况,用关键字distinct就可以去掉

example: select distinct * from table(表名) where (条件)

2,存在部分字段相同的纪录(有主键id即唯一键)

如果是这种情况的话用distinct是过滤不了的,这就要用到主键id的唯一性特点及group by分组

example:

select * from table where id in (select max(id) from table group by [去除重复的字段名列表,....])

3,没有唯一键ID

example:

select identity(int1,1) as id,* into newtable(临时表) from table

select * from newtable where id in (select max(id) from newtable group by [去除重复的字段名列表,....])

drop table newtable

(2)sql语句查询除ID扩展阅读

1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断

select * from people

where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)

2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录

delete from people

where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)

and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)

3、查找表中多余的重复记录(多个字段)

select * from vitae a

where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

Ⅲ 用sql语句查询除某个id外的所有

比如裂斗stu表中除森源早id=2外的所此雀有元组,id为int型
select * from stu
where id not in
(select id from stu
where id=2)

Ⅳ 怎样用SQL查询一个表的所有字段

可以用一句sql语句查询解决,如要查test表中的所有字段及类型

Selectb.nameasTableName,C.nameASTYPEfromsyscolumnsa,sysobjectsb,systypesc
wherea.id=b.id
andb.type='U'
anda.xtype=c.xtype
andb.name='TEST';

结果截图:

Ⅳ 用sql语句删除表中的某个ID

删除id值为80的行
delete from url where id = 80

Ⅵ sql查询除id外所有字段

select * from xxx
写好之后,右键,选择‘在编辑器中设计查询’,查询处理器将给出标准的大指查询语句,自动用字段替换*号,这样你复制出来后,自己芹仿返从select 后删掉id字段,这个是嫌饥最省事的办法了。

Ⅶ sql命令删除id用SQL语句批量删除指定ID

delete
from documents
where ID > 5000