当前位置: 代码迷 >> 其他数据库 >> SQLITE2.8.17 SELECT 从句有关问题
  详细解决方案

SQLITE2.8.17 SELECT 从句有关问题

热度:6767   发布时间:2013-02-26 00:00:00.0
SQLITE2.8.17 SELECT 从句问题
SQL code
--1,想在sqlite2.8.17中使用如下select语句:SELECT colA,colB FROM tableA WHERE (colA,colB) NOT IN (SELECT colA,colB FROM tableB);--报错:SQL error: near ",": syntax error--2,于是改为:SELECT colA,colB FROM tableA WHERE NOT EXISTS (SELECT * FROM tableB where tableA.colA=tableB.colA and tableA.colB=tableB.colB);--还是报错:SQL error: near "SELECT": syntax error--3,于是写了下面这条语句,但是我觉得应该是错误的,把结果集缩小了SELECT colA,colB FROM tableA WHERE (colA NOT IN (SELECT colA FROM tableB)) OR (colB NOT IN (SELECT colB FROM tableB));

对数据库操作不熟悉,请大家指点一下如何在sqlite2.8.17中完成如 1 所示的语句功能(在MySQL中无问题),简单高效的语句较好,谢谢大家!

------解决方案--------------------------------------------------------
select a.colA,a.colB from tableA a where (select count(*) from tableB b where a.colA=b.colA and a.colB=b.colB)=0
------解决方案--------------------------------------------------------
SELECT colA,colB FROM tableA WHERE colA NOT IN (SELECT colA FROM tableB)
and colb NOT IN (SELECT colb FROM tableB)
or
select a.* from tableA a left join tableb b on a.colA=b.colA and a.colb=b.colb
where b.colb is null
------解决方案--------------------------------------------------------
如果版本不支持子查询,那就用LEFT JOIN 配合IS NULL来实现了。

SELECT tableA.colA,tableA.colB
FROM tableA left join tableB on tableA.colA=tableB.colA and tableA.colB=tableB.colB
where tableB.tableA is null
  相关解决方案