PHP 查询 mysql 从 id 获取名称的数据
PHP query for mysql data getting name from id
从 previos 获取名称时遇到一些问题 table。
第一个 table 有 id 和 name。
Table 1
编号 |姓名
我得到结果的第二个 table 具有第一个 table
的 ID
Table 2
编号 | TABLE1_ID
我如何 运行 查询 Table 2 中的 ID 用于查找 Table 1 中的名称的位置?
SELECT ft.name FROM firsttable ft INNER JOIN secondtable st ON st.firsttable_id=ft.id WHERE st.id =123'
我假设你有两个 table,你指的是 "previous" table 作为 table 之一,对吧?
SQL 的重点实际上是根据一些主键和另一个 table 中的另一个外键加入 table。
您这样做的方式(至少我喜欢这样做)是使用 'JOIN' 关键字。
Table 1: ID=5, 名称="bla"
Table 2: ID=6, TABLE1_ID=5
给定 table2_id=6,加入 table2.TABLE1_ID=5 与 table1.id=5,所以 returns bla[=10 的名称=]
如果我没有正确回答,请更新您的问题。
从 previos 获取名称时遇到一些问题 table。 第一个 table 有 id 和 name。
Table 1
编号 |姓名
我得到结果的第二个 table 具有第一个 table
的 IDTable 2
编号 | TABLE1_ID
我如何 运行 查询 Table 2 中的 ID 用于查找 Table 1 中的名称的位置?
SELECT ft.name FROM firsttable ft INNER JOIN secondtable st ON st.firsttable_id=ft.id WHERE st.id =123'
我假设你有两个 table,你指的是 "previous" table 作为 table 之一,对吧?
SQL 的重点实际上是根据一些主键和另一个 table 中的另一个外键加入 table。
您这样做的方式(至少我喜欢这样做)是使用 'JOIN' 关键字。
Table 1: ID=5, 名称="bla" Table 2: ID=6, TABLE1_ID=5
给定 table2_id=6,加入 table2.TABLE1_ID=5 与 table1.id=5,所以 returns bla[=10 的名称=]
如果我没有正确回答,请更新您的问题。