作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要进行一次查询,得出配方、成分和方法表中的一列结果。我的示例表:
我正在获取食谱名称、食谱贡献者、食谱描述、食谱的成分及其方法
配方表
+--------------------------------------------------------------------+
|RECIPE ID | RECIPE NAME | RECIPE CONTRIBUTOR | RECIPE DESCRIPTION |
----------------------------------------------------------------------
| 1 |Chicken Curry | Me | Spicy and Hot |
+---------------------------------------------------------------------
成分表
+----------------------------------+
|ING ID | ING NAME | RECIPE ID |
------------------------------------
|1 |Chicken | 1 |
------------------------------------
|2 |Curry Powder | 1 |
+----------------------------------+
方法表
+----------------------------------+
|MET ID | METHOD | RECIPE ID |
------------------------------------
|1 |Boil Chicken | 1 |
------------------------------------
|2 |Cook curry | 1 |
+----------------------------------+
期望的输出:
+---------------+
|Output Column |
-----------------
Chicken Curry
Me
Spicy and Hot
Chicken
Curry Powder
Boil Chicken
Cook curry
+----------------+
最佳答案
据我了解,您希望将不同表中的不同列组合成单个列输出,以便在 Android 应用程序中使用它(之前的问题有 android 标签)。下面找到我的解决方案:
String query =
"select \"RECIPE NAME\" AS output from Recipe
union all
select \"RECIPE CONTRIBUTOR\" from Recipe
union all
select \"RECIPE DESCRIPTION\" from Recipe
union all
select \"ING NAME\" from Ingredients
union all
select METHOD from Methods";
Cursor cursor = sqLiteDatabase.rawQuery(query, null);
然后使用 cursor.getString(0);
迭代游标以检索每一行
关于mysql - 如何对 3 个表进行 1 次查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38350969/
我是一名优秀的程序员,十分优秀!