多个表中选择我有两个表:如何从基于条件
交表:
+-----+------------+--------------+
| id | title | details |
+-----+------------+--------------+
| 185 | some title | some details |
| 186 | some title | some details |
+-----+------------+--------------+
岗位类别:
+----+------------+---------+
| id | category | post_id |
+----+------------+---------+
| 1 | some title | 185 |
| 2 | some title | 186 |
+----+------------+---------+
当类别的用户点击,我想根据所选类别获取post table
的所有帖子。
我能够选择category
和post_id
这样的:
List<Map> postCategories2 = Base.findAll("select category, post_id from posts_categories where category = ?", request.queryParams("category_name"));
但我要的是使用category and post_id
从表中使用一个单一的查询,然后选择id, title, details
从post table
2即category table
所有我的信息是类别名称即request.queryParams("category_name")
注:id and post_id
有主键,外键关系
提示更换您的查询:'JOIN'表一起。 –