Error in query | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Error in query

Hi, I’m new in Sql Server (please be gentil if you see something stupid in my question). I have problems with this query: SELECT,
FROM personal.admin.modulo_perfil INNER JOIN personal.admin.modulos ON (personal.admin.modulo_perfil.id_modulo =
INNER JOIN personal.admin.perfiles ON (personal.admin.modulo_perfil.id_perfil =
CROSS JOIN personal.admin.perfil_usuario
INNER JOIN personal.admin.usuarios ON (personal.admin.perfil_usuario.id_usuario = )
INNER JOIN personal.admin.perfiles ON (personal.admin.perfil_usuario.id_perfil = )
WHERE (personal.admin.usuarios.login = ‘xxxxxxxx’) it returns this error: "Tables or functions ‘personal.admin.perfiles’ and ‘personal.admin.perfiles’ have the same exposed names. Use correlation names to distinguish them." Any Ideas?

Hi ya, if your connected as the user called admin to the database called personal, then you can leave off the personal.admin. bit from all the tables. the error itself means that you can’t have the same named table in the query twice without using an alias (a.k.a. correlation name) So change the query to
FROM personal.admin.modulo_perfil mp
INNER JOIN personal.admin.modulos m
ON (mp.id_modulo =
INNER JOIN personal.admin.perfiles p 1
ON (mp.id_perfil =
CROSS JOIN personal.admin.perfil_usuario pu
INNER JOIN personal.admin.usuarios u
ON (pu.id_usuario = )
INNER JOIN personal.admin.perfiles p2
ON (pu.id_perfil = )
WHERE (u.login = ‘xxxxxxxx’)
Twan, thanks for your answer (really faster) It works very good now. Regards