请使用以下查询帮助解决问题:
$sql = "SELECT email_id as name, competition_id, end_date FROM " . DB_PREFIX . "competition_winners, competition WHERE". DB_PREFIX . " competition.competition_id = ". DB_PREFIX ."competition_winners.competition_id";
我收到以下错误: 注意:错误:字段列表中的列'competition_id'不明确 错误号:1052 我正在使用opencart。我该如何解决?
答案 0 :(得分:0)
更多表的列名相同,为competition_id。
尝试在查询中添加前缀:
$sql = "SELECT email_id as name, c.competition_id as competition_id, end_date FROM " . DB_PREFIX . "competition_winners cw, competition c WHERE". DB_PREFIX . " competition.competition_id = ". DB_PREFIX ."competition_winners.competition_id";
答案 1 :(得分:0)
由于您的列competition_id
位于多个表中,因此您需要使用表alias
作为前缀以避免错误
SELECT competition_winners.email_id as name, competition.competition_id, competition.end_date
FROM " . DB_PREFIX . "competition_winners as competition_winners,
". DB_PREFIX . "competition as competition
WHERE competition.competition_id = competition_winners.competition_id";
答案 2 :(得分:0)
试试这个:
$sql = "SELECT email_id as name, c.competition_id, end_date FROM " . DB_PREFIX . "competition_winners cw, competition c WHERE cw.competition_id = c.competition_id";
错误的原因是两个表都有'competition_id'字段。所以你需要指定category_id字段的表名。