【发布时间】:2012-06-04 19:22:43
【问题描述】:
在我的数据库中,我有这些表
products
-------------
id | title |
-------------
1 Cheese
2 Milk
3 Water
等等……
products_to_city
-----------------------
city_id | product_id |
-----------------------
1 1
1 2
2 3
3 1
3 1
我正在使用这个 sql 查询来获取结果
SELECT
p.id,
p.title
FROM products p
LEFT JOIN products_to_city ptc ON ptc.id = 1
问题是上面的查询从表中获取所有数据,而不是仅在 city 为 1 的地方获取数据
我做错了什么?
【问题讨论】:
-
您想在查询中用 1 说什么? id 还是字段号?