0

I am making a database and I have been trying to get this done for a good amount of time.

SELECT clients.nombre, clients.zona 
FROM developmentrequest,potentialclients, users
INNER JOIN clients ON clients.id_clients = developmentrequest.id_clients
INNER JOIN users ON clients.id_user = users.id
WHERE users.id =4 AND developmentrequest.id_states=3

UNION

SELECT potentialclients.nombre, potentialclients.zona
FROM developmentrequest,potentialclients, users
INNER JOIN potentialclients ON potentialclients.id_potentialclients = developmentrequest.id_potentialclients
INNER JOIN users ON potentialclients.id_user = users.id
WHERE users.id =4 AND developmentrequest.id_states=3

this is the code I have been working on and it gives the problem: #1066 - Not unique table/alias: 'potentialclients', now I have tried naming potentialclients with an alias like pc1 but it starts giving other errors with other columns, I dont know what to do :C

B Kalra
  • 821
  • 6
  • 17
  • 4
    Avoid mixing comma-separated tables and the `JOIN` clause in the same query. – The Impaler Jun 29 '22 at 18:35
  • 4
    Avoid using comma-separated tables at all and use `JOIN` clauses exclusively. – David Jun 29 '22 at 18:35
  • 1
    For a self-join you **must** use table aliases. Your `FROM developmentrequest,potentialclients, users` constitutes an implicit `INNER JOIN` of the three tables. – PM 77-1 Jun 29 '22 at 18:35
  • Mixing [explicit and implicit joins](https://stackoverflow.com/q/44917/1422451), you are joining some tables *twice* in each `SELECT` statement without aliasing to distinguish between duplicate pairs. – Parfait Jul 01 '22 at 22:51

0 Answers0