且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

mysql 查询显示来自一个 ID 列的多个表

更新时间:2023-11-26 22:44:52

您必须加入两次.为表格指定不同的别名,以便您区分它们.

You have to join twice. Give the table different aliases so you can distinguish them.

SELECT h1.name as host_name, h2.name AS template_name
FROM hosts_template AS t
JOIN hosts AS h1 ON t.hostid = h1.hostid
JOIN hosts AS h2 ON t.hosttemplateid = h2.hostid