2016-06-16 8 views
0

ich mit dieser Abfrage stucked haben:Android: SQLiteException: keine solche Spalte, wenn ich Unterabfragen verwenden

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) 

Die Abfrage funktioniert in "DB-Browser für SQLite" in Ordnung, aber in meiner app bekomme ich einen Fehler, Hier ist der Fehler in 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) 

Gibt es irgendwelche Ideen, wie kann ich das beheben? Danke;)

Antwort

1

In SQL verwenden Zeichenfolgen einfache Anführungszeichen. Doppelte Anführungszeichen werden verwendet, um Tabellen- oder Spaltennamen zu umgehen.

(SQLite ermöglicht beides in beiden Kontext, aber das hilft nicht in einem mehrdeutigen Kontext.)

+0

Vielen Dank, es hat geholfen! – Nemesis

Verwandte Themen