#1066 - Not unique table/alias: ? What can I do?

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

Answers


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

  • the from XXX clause (that is your first table available brought in)
  • the 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.


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

Need Your Help

Capture Window (Alt-Print Screen) of Context Menu

windows screenshot bug-tracking screen-capture printscreen

As everyone knows, sometimes developers have to document stuff. Or capture some stuff for filing bug reports.

Use 'import module' or 'from module import'?

python python-import

I've tried to find a comprehensive guide on whether it is best to use import module or from module import? I've just started with Python and I'm trying to start off with best practices in mind.