Php 从id相同的其他表中提取名称/值
分销商表Php 从id相同的其他表中提取名称/值,php,mysql,sql,select,Php,Mysql,Sql,Select,分销商表 name id usf south 1 usf north 2 usf east 3 usf west 4 ogi表 distributor itemname 1 cheese 1 apples 3 oranges 2 pineapples 目前,我在“ogi表”的“distributor”列中为页面上的每个itemna
name id
usf south 1
usf north 2
usf east 3
usf west 4
ogi表
distributor itemname
1 cheese
1 apples
3 oranges
2 pineapples
目前,我在“ogi表”的“distributor”列中为页面上的每个itemname显示了编号。但是,我想将此编号更改为“distributors表”中的正确分销商名称。我该怎么做
感谢您的帮助。本教程将向您展示如何将其存档
SELECT
ogi.itemname,
distributors.name AS distributor
FROM
ogi
INNER JOIN
distributors
ON
ogi.distributor = distributors.id
+1用于格式良好的示例。这是完美的。不需要修改我的任何php代码。谢谢你的帮助!我认为这是一个内部连接,但我不太确定如何实现它(对mysql来说有点新)。再次感谢!
SELECT
ogi.itemname,
distributors.name AS distributor
FROM
ogi
INNER JOIN
distributors
ON
ogi.distributor = distributors.id