mysql里not in语句怎么写
时间:2007-05-28 来源:edelwei
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%'
但在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%'
相关阅读 更多 +