Skip to content
Advertisement

Getting Duplicate column name ‘Unknown’ error when executing insert statement , mysql

Created a new DB schema / tables and tried to insert values. My insert query as follows

Here i get following error after my first insert query, but second insert query worked fine.;

What im doing wrong here?

Advertisement

Answer

I’m guessing if you alias your columns differently it will work out:

The second query doesn’t crash because the strings are different

You haven’t provided an alias for the strings so my reasoning is that MySQL tries to help out by creating an alias from the string, but it creates identical aliases

SQLServer wouldn’t let you do this; it would give a error that the column in the subquery needs an alias (and it wouldn’t let you declare two column aliases that are the same). Aliases are required for columns in a sub query so that you can unambiguously refer to the columns in an outer query – think about this one:

What should MySQL show you? 1 or “hello”?

Hence the reason why subquery columns need unique aliases

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement