0
我在php中完成了餐館搜索中的三個表。搜索選項可以通過複選框狀態按多種類型進行過濾。某些餐廳可能會屬於多種類型,並且會在type_stack表中有多個條目。防止在mysql中返回重複的行
Table1 - **restaurant**
------+----------+----------
id + name + place
------+----------+----------
1 rest1 ny
2 rest2 la
3 rest3 ph
4 rest4 mlp
Table2 - **r_type**
------+----------+----------
id + name + code
------+----------+----------
1 type1 0
2 type2 1
3 type3 2
4 type4 3
Table3 - **type_stack**
------+----------+----------
id + rest_id + type
------+----------+----------
1 2 2
2 4 1
3 1 2
我想獲得所有符合用戶所選類型的餐廳。但問題是多次獲得同一家餐廳。我只想要一次顯示一行。
這是我的查詢
SELECT restaurant.name, restaurant.place FROM restaurant, type_stack WHERE restaurant.id = type_stack.rest_id AND type_stack.type = '0' AND type_stack.type = '1' AND type_stack.type = '2' LIMIT 0 , 30
查詢是基於複選框狀態下進行!在這種情況下,類型0,1和2被選中。