sql多条件查询语句

来源:百度知道 编辑:UC知道 时间:2024/05/09 06:00:25
在我的MYsql库中有一个user表 表中有个字段username 数据中有用户名为 aaa bbb ccc ddd eee fff ggg hhh这样的数据,我想删除用户名不等于AAA bbb ccc ddd eee的数据。
请问这样的sql语句怎么写,
我使用select from user where username='aaa' or username='bbb' 这种语句是可以查询出来的 但是 换成select from user where username<>'aaa' or username<>'bbb' 这样的语句就不行了。就查询不出来了。

select * from user where username not in ('aaa', 'bbb','ccc')

另外, 你的第二种写法中间要换用and不能用or

select from user where username<>'aaa' and username<>'bbb'

这个呀,你是想查出什么呢?
要是查找aaa,bbb这些人的话,你可以用
select from user where username='aaa' or username='bbb'
要是找那些不在这里的那些人可以试试
select from user where username<>'aaa' or username<>'bbb' 找到是会是ccc,ddd。。。。这些人

这个select from user where username<>'aaa' and username<>'bbb'是查不到结果的

要是想删除的为什么不用delete语句呢

select * from user where username not in ('aaa', 'bbb','ccc','ddd','eee')
这是查询出相关数据,如果要删除:

delete from user where username not in ('aaa', 'bbb','ccc','ddd','eee')

dete from user where username not in ('aaa', 'bbb','ccc','ddd','eee')