Reputation: 3683
hi i have a prpblem in my sql statement :( I get the error:
#1066 - Not unique table/alias: 'VERANSTALTUNG'
here is my code:
select VERANSTALTUNG.v_name, V_TYP.typ, RAUM.raumname, GEBEAUTE.gebeaute_name From VERANSTALTUNG
JOIN VERANSTALTUNG on VERANSTALTUNG.v_typ_id=V_TYP.v_typ_id
JOIN VERANSTALTUNG on VERANSTALTUNG.raum_id=RAUM.raum_id
JOIN RAUM on RAUM.gebeaute_id=GEBEAUTE.gebeaute_id
Upvotes: 1
Views: 1280
Reputation: 24959
Here is a starting point. V1, V2, V3 are aliases, if you even need them all.
You need to bring in tables before you reference them (not in the first select row, but in the joins after the select row).
In other words, you can reference them in the select column list. But you cannot reference them in joins if they are not brought in.
You can't reference GEBEAUTE
before you have brought it in
there are 2 ways of bringing it in
from
XXX clause (that is your first table available brought in)join
XXX clause (that brings in tables 2 and beyond).
select VERANSTALTUNG.v_name, V_TYP.typ, RAUM.raumname, GEBEAUTE.gebeaute_name
From VERANSTALTUNG V1
JOIN VERANSTALTUNG V2 on V2. something
JOIN VERANSTALTUNG V3 on V3. something
JOIN RAUM on RAUM.gebeaute_id=GEBEAUTE.gebeaute_id -- error here still, see below
note you still haven't brought in V_TYP
or GEBEAUTE
it's a mess. Less of a mess, but inching toward happiness.
Here is a simple illustration of it
line1: select A.col1,B.col2,C.col3
line2: from table1 A
line3: join table2 B on B.blahblah=A.something
line4: join table3 C on C.typ_id=D.month_id
It look good until line4. Because table D
is not brought in yet.
Upvotes: 2
Reputation: 1028
You should use another alias for VERANSTALTUNG
table in join:
select VERANSTALTUNG.v_name, V_TYP.typ, RAUM.raumname, GEBEAUTE.gebeaute_name
From VERANSTALTUNG
JOIN VERANSTALTUNG as t1 on t1.v_typ_id=V_TYP.v_typ_id
JOIN VERANSTALTUNG as t2 on t2.raum_id=RAUM.raum_id
JOIN RAUM on RAUM.gebeaute_id=GEBEAUTE.gebeaute_id
Upvotes: 1