为什么错误#1066 - 不唯一的表/别名:'cat_rapoarte'

为什么错误#1066  - 不唯一的表/别名:'cat_rapoarte'

问题描述:

I'm working on a student->parent->teacher grading system for the school I work at and while using MySQL I have received this error. Why?

SELECT `cat_materii`.* 
    FROM `cat_rapoarte` 
INNER JOIN `cat_rapoarte` on
`cat_materii`.`m_id`=`cat_rapoarte`.`rap_m_id` 
    WHERE `cat_rapoarte`.`k_id` = '7fbXe1dvltedEkIXELc8Q1NeMkKRb3pi' AND (data BETWEEN '2015-11-01' AND '2015-11-30') GROUP BY `rap_m_id`

You had the same table twice in the join clause. See the commented part in the query.

SELECT `cat_materii`.* 
FROM `cat_materii` --`cat_rapoarte` 
INNER JOIN `cat_rapoarte` on `cat_materii`.`m_id`=`cat_rapoarte`.`rap_m_id` 
WHERE `cat_rapoarte`.`k_id` = '7fbXe1dvltedEkIXELc8Q1NeMkKRb3pi'
AND (data BETWEEN '2015-11-01' AND '2015-11-30') 
GROUP BY `rap_m_id`