我有两张桌子:
items表:
id title unique_flat_title
---------------------------------------------
1 post 1 post_1
2 post 2 post_2
3 category 1 category_1
4 post 3 post_3
5 post 4 post_4
6 category 2 category_2
7 post 5 post_5item_connection表:
post_id category_id
----------------------------------
1 3
1 6
5 6
7 3
4 3
4 6我想打印连接到unique_flat_title为category_2的另一个项目的所有项目。这有可能吗?谢谢你提前提供帮助!
编辑:
因此,假设我需要unique_flat_title是category_1的帖子列表。
因此,我需要下面的列表:
category_flat_title post_id post_title
------------------------------------------------------
category_1 1 post 1
category_1 7 post 5
category_1 4 post 3发布于 2013-11-18 16:34:01
您可以将"items“表加入到"items_connection",使用来自第一个的ID来匹配第二个条目的CATGEORY_ID。然后,您可以再次将其加入到"items“表中,使用第二个的POST_ID来匹配第三个条目的ID。看起来是这样的:
SELECT A.unique_flat_title As category_flat_title
, C.id As post_id , C.unique_flat_title As post_title
from items A
join item_connection B on B.category_id = A.id
join items C on C.id=B.post_id https://stackoverflow.com/questions/20050511
复制相似问题