Android:SQLiteException:当我使用子查询时没有这样的列

时间:2016-06-16 16:09:09

标签: android sqlite

我一直坚持这个问题:

SELECT * FROM (

SELECT tab._id t_id, tab.name name, pics.pic1 pic FROM mushrooms tab
JOIN mushrooms_pics pics ON t_id = pics.id WHERE t_id IN 
(SELECT item_id FROM coordinate WHERE type = "mushrooms") UNION

SELECT tab._id t_id, tab.name name, pics.pic1 pic FROM berries tab
JOIN berries_pics pics ON t_id = pics.id WHERE t_id IN
(SELECT item_id   from coordinate WHERE type = "berries") UNION

SELECT tab._id t_id, tab.name name, pics.pic1 pic FROM herbs tab
JOIN herbs_pics pics ON t_id = pics.id WHERE t_id IN 
(SELECT item_id from coordinate WHERE type = "herbs")

) 
LEFT JOIN coordinate c ON t_id = c.item_id WHERE t_id IN 
(SELECT item_id from coordinate)

查询在" DB浏览器中适用于SQLite",但在我的应用程序中我收到错误,这里是LOGCAT中的错误:

android.database.sqlite.SQLiteException: no such column: herbs (code 1): , while compiling: SELECT name FROM( SELECT tab._id t_id, tab.name name, pics.pic1 pic FROM mushrooms tab JOIN mushrooms_pics pics ON t_id = pics.id WHERE t_id in (SELECT item_id from coordinate WHERE type = mushrooms) UNION SELECT tab._id t_id, tab.name name, pics.pic1 pic FROM berries tab JOIN berries_pics pics ON t_id = pics.id WHERE t_id in (SELECT item_id from coordinate WHERE type = berries) UNION SELECT tab._id t_id, tab.name name, pics.pic1 pic FROM herbs tab JOIN herbs_pics pics ON t_id = pics.id WHERE t_id in (SELECT item_id from coordinate WHERE type = herbs) ) LEFT JOIN coordinate c on t_id = c.item_id WHERE t_id in (SELECT item_id from coordinate)

有什么想法我该如何解决这个问题? 谢谢;)

1 个答案:

答案 0 :(得分:1)

在SQL中,字符串使用单引号。 双引号用于转义表名或列名。

(SQLite允许在任一上下文中使用,但这对于模糊的上下文没有帮助。)