[转]mysql里not in语句怎么写

来源:互联网 发布:sql insert 多条数据 编辑:程序博客网 时间:2024/05/22 06:19

使用mysql中经常会遇到的问题,记录下来

 

转自: http://database.e800.com.cn/articles/2007/630/1183147360019880660_1.html

 

 

 

select bid from board where not in (select bid from favorite)
但在mysql里就提示SQL语句的语法不对,“...near ''select bid from favorite)''

--------------------------------------------------------------------------------
在MySQL中下列语句还不能工作:
SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
然而,在很多情况下,你可以重写查询,而不用子选择:
SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL
select a.user_name from tmp_user_user a left outer join briousr2 b on a.user_name=b.user_name where b.user_name is null and a.user_name not like ''%0%''
原创粉丝点击