看看以下查询:
查询:
SELECT
[10_Departments].[DepID] AS DepID,
[70_Types].[TypeName] AS TypeName,
[10_Departments].[DepName] AS DepName,
[10_Departments].[Description] AS Description,
[10_Departments].[HTML] AS HTML,
[70_Pictures].[PictureFilename] AS PictureFilename,
[40_AvailableDeps].[DepID] AS AvailDepID
FROM (([70_Types]
INNER JOIN (([80_Deps_Pictures]
INNER JOIN [10_Departments]
ON [80_Deps_Pictures].[DepID] = [10_Departments].[DepID])
INNER JOIN [70_Pictures]
ON [80_Deps_Pictures].[PicID] = [70_Pictures].[PicID])
ON [70_Types].[TypeID] = [10_Departments].[Type])
LEFT JOIN [40_AvailableDeps]
ON [10_Departments].[DepID] = [40_AvailableDeps].[DepID])
WHERE [10_Departments].[Type] = 2
ORDER BY [10_Departments].[DepID]
在第二个版本中,先前在Android 4.2.2和Android 7.0中安装了相同数据库的查询是完美的,但在第一个中,它报告了未找到[10_Departments].[DepID]
列的错误。我在[10_Departments].*
之前进行了选择,并且它报告未找到表[10_Departments]
。事实是,在两种SDK情况下都存在,因为它是同一个数据库...
任何有见识的人吗?
谢谢
编辑-在用于SQLLite的DB Browser和SQLite Expert Personal 5中,查询都可以毫无问题地针对数据库执行。
Edit#2-应用程序连接到数据库,就像在另一个活动中一样,我从数据库中读取数据没有问题(普通查询-无联接查询-不在同一张表中)。
Edit#3-我试图通过普通查询(例如“ SELECT * FROM [10_Departments]”)从表中读取记录,并且执行起来没有问题(表在那里)。
答案 0 :(得分:0)
这是使用MS Access查询构建器生成的具有多个联接的查询中的典型错误(由于某些奇怪的原因,它在联接周围加上括号,这限制了某些SQLite版本中其他表的列的可见性。)
只需删除所有括号,然后逐个进行连接即可。如果您有外部联接,则必须确保以后的联接不会删除具有NULL值的行,通常是最后写入它们。
请注意,在两个具有相同名称的列上联接时,使用USING更为简单:
FROM [80_Deps_Pictures]
JOIN [10_Departments] USING (DepID)
JOIN [70_Pictures] USING (PicID)
JOIN [70_Types] ON [70_Types].[TypeID] = [10_Departments].[Type]
LEFT JOIN [40_AvailableDeps] USING (DepID)