我写了一个提取可用竞赛的查询,我的表有一个名为name
的公共字段,因此我使用alias
在最终结果中识别此字段:
$query = "SELECT c.*,
c.name AS competition_name,
s.name AS season_name
FROM competition c
LEFT JOIN competition_seasons s ON c.id = s.competition_id
WHERE country_id = :country_id";
问题是查询将返回字段name
:
{
"id": "1093",
"country_id": "1",
"name": "Premier League",
"category": "1",
"competition_name": "Premier League",
"season_name": "2018"
}
这是competition_name
的重复,我做错了什么?
答案 0 :(得分:2)
您SELECT c.*
,其中包含c.name
:
您的查询扩展为:
SELECT
c.id, c.country_id, c.name, c.category,
c.name AS competition_name, s.name AS season_name
FROM ...
所以SELECT
字段name
两次。