Page 1 of 1

1066 error on a SELECT query

Posted: Mon Mar 28, 2005 12:13 am
by Stryks
Hey all,

I'm trying to get a query working, but I cant seem to join the three tables I need without getting a 1066 - Not unique table/alias: 'tbl_master_items' error.

Here's my query (excuse the format - navicat)

Code: Select all

SELECT 
  `tbl_master_items_type`.`name`,
  `tbl_master_items_type`.`MT_PK`
FROM
  `tbl_master_items_type`
 JOIN `tbl_master_items` ON (`tbl_master_items_type`.`MT_PK` = `tbl_master_items`.`MT_ID`),
  `tbl_vendor_menu_items`
  JOIN `tbl_master_items` ON (`tbl_vendor_menu_items`.`MI_ID` = `tbl_master_items`.`MI_PK`)
I dont really understand what the issue is. From what I can tell in my searching around, this issue seems to only relate to INSERT queries.

I'm using mySQL 3.23.49 (according to phpinfo).

Cheers

Posted: Mon Mar 28, 2005 12:38 am
by feyd

Code: Select all

SELECT
  a.`name`, a.`MT_PK`
FROM
  `tbl_master_items_type` a
INNER JOIN
  `tbl_master_items` b
ON
  a.`MT_PK` = b.`MT_ID`
INNER JOIN
  `tbl_vendor_menu_items` c
ON
  c.`MI_ID` = b.`MI_PK`

Posted: Mon Mar 28, 2005 12:43 am
by Stryks
Holy crap! Why did that work?

Oh, so with the FROM and JOIN statements you are assigning an alias and referring to them throughout the rest of the query.

Cool. Thanks 8)