Search code examples
sqlsql-serveraliasesmssql-jdbc

SQL Server queries to table which name matches the command name


SELECT role.name, role_privelege.privelege 
FROM role
JOIN role ON role.id = role_privelege.id

breaks with an error:

[Error Code: 1013, SQL State: S0001]
The objects "role" and "role" in the FROM clause have the same exposed names. Use correlation names to distinguish them.

With aliases it also doesn't work.

As well DbVizualizer highlights the role in role.name for example as command name


Solution

  • You mis-typed the joined table:

    SELECT role.name, role_privelege.privelege 
    FROM role
    JOIN role_privelege ON role.id = role_privelege.id