MySQL Forums
Forum List  »  Newbie

simple problem - error 1066 Not Unique table/alias and Conditional
Posted by: Marco Aurélio rodaweb
Date: July 30, 2014 05:59PM

Probably an easy problem. Two tables. I want to select 2 names from Person table. I think a join table would be overboard for this simple requirement, let me know.

person (table)
- id_person
- name

place (table)
- id_place
- name
- id_person1 [fk person.id_person]
- id_person2 [fk person.id_person]

I try
SELECT place.name AS place_name, person.name AS name1, person.name AS name2
FROM place
INNER JOIN person ON place.id_person1=person.id_person
INNER JOIN person ON place.id_person2=person.id_person

ERROR 1066 (42000): Not unique table/alias: 'person'


Well, I can't refer to the PERSON table twice in the same query without giving it an alias in at least one of the joins.
The solution is:

SELECT place.name AS place_name,
person.name AS name1,
person.name AS name2
FROM place
INNER JOIN person
ON place.id_person1=person.id_person
INNER JOIN person as p2
ON place.id_person2=p2.id_person


And if I want just a query only something like place.id_place = 3


Can anyone help me?
Thanks all

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.