mysql error 1066

僤鯓⒐⒋嵵緔 提交于 2019-12-14 03:27:22

问题


$id=$_GET["id"];
$query= "
SELECT
blomster_produkter.blomster_produkt_id,
blomster_produkter.blomster_produkt_navn,
blomster_produkter.blomster_produkt_pris
FROM
blomster_produkter
INNER JOIN blomster_produkter ON 
blomster_produkter.FK_blomster_produkt_id=blomster_produkter.blomster_produkt_navn     
blomster_produkter.FK_blomster_produkt_id=blomster_produkter.blomster_produkt_pris
blomster_produkter.FK_blomster_produkt_id=blomster_produkter.blomster_produkt_id
WHERE FK_blomster_kategori_id=$id";

Why is this throwing me an mysql error 1066?

(also sorry if i am missing some important stuff, this is the first question i am asking on stackoverflow)


回答1:


0.1 seconds of googling: "mysql error 1066" - not unique table name/alias

    FROM
    blomster_produkter   <--table #1
    INNER JOIN blomster_produkter ON   <-table #2

you cannot join a table to itself, or re-use the same table name in a join, without using an alias:

FROM blomster_produkter
INNER JOIN blomster_produkter AS someothername ON
                             ^^^^^^^^^^^^^^^^^--- the alias

and then changing table references as necessary in your join conditions.

As well, note that you are wide open to sql injection attacks. Enjoy having your server pwn3d.




回答2:


Error 1066 is "Not Unique table/alias"

this is because you are join a table with itself without making aliases, you must do aliases like:

SELECT
    bp1.blomster_produkt_id,
    bp1.blomster_produkt_navn,
    bp1.blomster_produkt_pris
    FROM
    blomster_produkter bp1
    INNER JOIN blomster_produkter bp2 ON
    bp1.FK_blomster_produkt_id=bp2.blomster_produkt_navn [...]


来源:https://stackoverflow.com/questions/13711291/mysql-error-1066

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!