我有两个桌子
https://stackoverflow.com/questions/38969419/ios-how-can-enable-or-disable-rotate-on-each-uiviewcontroller
我像这样加入两者:
Table name: place
Columns: placeid, name
Data: 1, My Favourite Donut Place
Table name: category
Columns: categoryid, name, placeid
Data: 1, Donuts, 1
2, Coffee, 1
3, Hot Chocolate, 1
会得到这样的结果:
select p.name as place, c.name as category from place p join category c on p.placeid=c.placeid
现在,我想搜索提供咖啡的地方:
place category
My favourite donut place Donuts
My favourite donut place Coffee
My favourite donut place Hot Chocolate
结果如下:
select p.name as place, c.name as category from place p join category c on p.placeid=c.placeid where c.name = 'Coffee'
但是我仍然想显示“我最喜欢的咖啡甜甜圈店”的所有不同类别,即“甜甜圈”和“热巧克力”。
要实现这一目标的最佳方法是什么?
答案 0 :(得分:0)
您只需对类别进行第二个位置连接即可获得所有类别,虽然在这种情况下连接顺序并不重要,但我发现这种顺序更清楚了。
SELECT p.name AS place, placeCategories .name AS category
FROM category AS filterCategory
INNER JOIN place AS p ON filterCategory.placeid=p.placeid
INNER JOIN category AS placeCategories ON p.placeid=placeCategories.placeid
WHERE filterCategory.name = 'Coffee'