2015-09-05 65 views
0

我無法運行在SQLite的Android的查詢時,它拋出以下錯誤:WHERE使用另一臺子句NOT IN

android.database.sqlite.SQLiteException: no such table: table1.item1 (code 1): ,while compiling: SELECT * from table1, table2 where table1.item1 not in table2.item1

我的原始查詢爲:

Database.rawQuery("SELECT * from "+ TABLE1 +", " 
    +TABLE2+" where "+ TABLE1 +"" + "."+ ITEM1 +" not in " 
      + TABLE2 +"."+ ITEM1, null); 

字符串常量:

TABLE1= "table1", TABLE2="table2", ITEM1= "item1" 

我想要table1中的所有行,其item1不在table2中的item1值列表中。

我需要添加一些GROUP BY語句嗎?

回答

2

如果這是你在找什麼,這將是您的查詢:

SELECT * FROM table1 WHERE item1 NOT IN (SELECT item1 FROM table2) 

你「SELECT * FROM表1,表2」會給你一個組合的每一個返回的Table 1和Table記錄。這並不是經常的意圖。