我使用以下方法从两个表中获取数据:
SELECT p.id, p.title, p.event_date, a.name, p.location_id
FROM ixrsk_eb_events p
INNER JOIN ixrsk_eb_locations a on p.location_id = a.id
这很好用。
现在另外,我想要有列标题。
在结果之上:“ID”(col p.id
)、“标题”(col p.title
)、“日期”(col p.event_date
)和“位置”(col a.name
)。
和栏p.location_id
根本不应该显示(没有标题,没有数据)。
我该怎么做?
最佳答案
您可以使用别名来更改显示的列的名称:
SELECT
p.id AS ID,
p.title AS Title,
p.event_date AS Date,
a.name AS Location
FROM ixrsk_eb_events p
INNER JOIN ixrsk_eb_locations a on p.location_id = a.id
然后忽略您不想显示的列。
关于MySQL来自两个表的数据: Adding column headings to output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53224021/