MySQL & PHP - Not unique table/alias

前端 未结 4 1140
攒了一身酷
攒了一身酷 2021-02-12 12:21

I get the following error listed below and was wondering how do I fix this problem.

Not unique table/alias: \'grades\'

Here is the code I think

相关标签:
4条回答
  • 2021-02-12 12:46

    You need to use an alias if you're using the same name twice:

    SELECT FROM grades g1 ... 
    JOIN grades g2 ON g1.id = g2.grade_id ...
    

    Be sure that you intended to use the same name twice, and didn't mistakenly enter the same name twice.

    0 讨论(0)
  • 2021-02-12 12:50

    The problem seems to be here:

    SELECT COUNT(*) 
    FROM grades 
    JOIN grades ON grades.id = articles_grades.grade_id
    WHERE articles_grades.users_articles_id = '$page'"
    

    You are trying to join the table grades to itself. You probably meant to join with articles_grades.

    0 讨论(0)
  • 2021-02-12 12:52

    I thin that in the $sql2 query the second table isn't grades but article_grades. so it will be:

    "SELECT COUNT(*) 
             FROM grades 
             JOIN articles_grades ON grades.id = articles_grades.grade_id
             WHERE articles_grades.users_articles_id = '$page'"
    
    0 讨论(0)
  • 2021-02-12 12:54

    it's saying that because you have table name grades in the query twice

    0 讨论(0)
提交回复
热议问题