我尝试通过 mysql 连接合并来自 2 个表的数据,但我看起来像是,我根本没有收到来自第二个表的结果。
表结构 #1 (site_hosters);
+------------+--------------+--------+
| host_id | name | prio |
+------------+--------------+--------+
| 1 | site.com | 0 |
+------------+--------------+--------+
表结构 #2 (site_date);
+------------+--------------+--------+
| id | hoster | page |
+------------+--------------+--------+
| 1 | site.com | http:..|
+------------+--------------+--------+
我试图得到的结果是像'id, host_id, name, ....etc';
当我尝试执行以下查询时,它不会在查询结果中包含 host_id 和 prio。 查询起来,join 一点作用都没有。
我的查询:
SELECT
site.id,
site.hoster,
site.page,
FROM site_data as site
INNER JOIN site_hosters hoster
ON site.hoster = hoster.name
我希望有人能帮我解决这个问题。
亲切的问候, 尼克
最佳答案
您必须命名要选择的列。像这样添加 site_hosters
列:
SELECT
site.id,
site.hoster,
site.page,
hoster.host_id,
hoster.prio
FROM site_data as site
INNER JOIN site_hosters hoster ON site.hoster = hoster.name
关于MySql 查询合并来自 2 个表的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10026925/