我有两张桌子:
帖子表:
+-----+------------+--------------+
| 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"));
但我想要的是使用单个查询并从id, title, details
表2 中选择,即post table
category and post_id
category table
我拥有的所有信息都是类别名称,即request.queryParams("category_name")
注意:id and post_id
有主键-外键关系