SQL ERROR: 1066 not unique table/alias

160 Views Asked by At

Hi I'm stuck on this query

SELECT c1.ID FROM cliente JOIN corsa AS c1 ON corsa.cliente_ID = cliente.ID_cliente, cliente JOIN corsa AS c2 ON corsa.cliente_ID = cliente.ID_cliente WHERE c1.tariffa = c2.tariffa AND c2.ID_cliente = 1 AND c2.data_corsa = "2012-06-20";

I get error 1066 not unique table/alias: 'cliente'. I understood there is a problem in the FROM statement in which I call 'cliente' twice. I just can't figure out how to make it work.

I tried this

SELECT DISTINCT c1.* FROM cliente INNER JOIN corsa AS c1, cliente c2 INNER JOIN corsa AS c3 WHERE c1.tariffa = c3.tariffa AND c3.cliente_ID = 1 AND c3.data_corsa = "2012-06-20";

and it seems to work, but I'm not so sure of it.

Thanks

0

There are 0 best solutions below