我正在尝试实现子查询,但收到错误only a single result allowed
。我在查询中实现错误还是语句本身错了?
搜索应返回与嵌套选择语句
中生成的代码匹配的配方名称查询
return db.rawQuery("select recipe_name from recipes where recipe_code in (select ingredients.recipe_code, ingredients._id from ingredients inner join kitchen on kitchen.ingredient_name = ingredients.ingredient_name)", null);
错误
Caused by: android.database.sqlite.SQLiteException: only a single result allowed for a SELECT that is part of an expression (code 1): , while compiling: select recipe_name from recipes where recipe_code in (select ingredients.recipe_code, ingredients._id from ingredients inner join kitchen on kitchen.ingredient_name = ingredients.ingredient_name)
12-10 22:19:04.238 29209-29209 / com.example.rory.prototypev2 E / AndroidRuntime:at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
答案 0 :(得分:0)
我认为问题在于您尝试为子查询返回多个列,并且只允许返回一列。删除成分._id
查询将返回
recipe_code, _id
123 5
您只需要代码。