Mysql一行左连接


Mysql one row left join

我有两个表:

product_list :
id_list | name_product  | price |
1       |    test01     |   20  |
10      |    test02     |   50  |

people :
people_id | people_use_product  | people_list
35        |   test01            | 1
36        |   test02            | 1

可以访问id为1和10的列表。但是同样的乘积可以在这两行中。(因为列表可以用于许多列表中的人)。我只需要得到一行。(=产品的价格)

SELECT * FROM people
INNER JOIN product_list ON (id_list=1 or id_list=10)
WHERE people_list = 1
LIMIT 0,100

我怎么能只有一行?

您的请求是错误的。您没有指定适当的连接条件。JOIN实际上是两个表的笛卡尔积,仅此而已。

如果人们。People_list是product_list的外键:

SELECT * FROM people
INNER JOIN product_list ON (id_list = people_list) -- valid JOIN condition between two tables
WHERE ids_list = 1

可能更接近您的需要。

然而,我不太了解你的数据结构和你的实际需求,所以你必须改进一下查询,我猜…