MySql: Column 'XXXX' in field list is ambiguous 错误

[Err] 1052 - Column 'XXXX' in field list is ambiguous

例如:

SELECT
    id,
    a.name,
    price,
    `describe`,
    schoolid,
    `subject`
FROM
    tariffpackages a,
    schooluser b
WHERE
    a.schoolid=b.Schoolid

出现错误:

[SQL]SELECT
    id,
    a.name,
    price,
    `describe`,
    schoolid,
    `subject`
FROM
    tariffpackages a,
    schooluser b
WHERE
    a.schoolid=b.Schoolid

[Err] 1052 - Column 'schoolid' in field list is ambiguous

原因是:

tariffpackages表和schooluser表中都有schoolid字段。

解决方法:

SELECT
    id,
    a.name,
    price,
    `describe`,
    a.schoolid,
    `subject`
FROM
    tariffpackages a,
    schooluser b
WHERE
    a.schoolid=b.Schoolid

 

posted @ 2016-06-29 15:59  邓晓晖  阅读(10380)  评论(0编辑  收藏  举报