我在SQLite语法方面遇到了一些麻烦。
我能够让以下工作:
create table A as select * from DocumentFolders where DocumentFolders.folderId =202
create table B as select * from DocumentFolders where DocumentFolders.folderId =35
create table C as select * from A join B on A.documentId = B.documentId
但我不能让这个复合语句起作用
select * from DocumentFolders where DocumentFolders.folderId =202 as A join select *
from DocumentFolders where DocumentFolders.folderId =35 as B on A.documentId =
B.documentId
希望得到一些提示吗?
由于
标记
答案 0 :(得分:0)
使用连接时,您仍然只有一个SELECT语句,它只能有一个FROM / WHERE子句:
SELECT *
FROM DocumentFolders AS A
JOIN DocumentFolders AS B USING (documentId)
WHERE A.folderId = 202
AND B.folderId = 35
或者,您可以将完整的查询移动到子查询中:
SELECT *
FROM (SELECT * FROM DocumentFolders WHERE folderId = 202)
JOIN (SELECT * FROM DocumentFolders WHERE folderId = 35) USING (documentId)
在SQLite 3.8.3或更高版本中,您可以使用公用表表达式:
WITH
A AS (SELECT * FROM DocumentFolders WHERE folderId = 202),
B AS (SELECT * FROM DocumentFolders WHERE folderId = 35)
SELECT *
FROM A
JOIN B USING (documentId)