1066 error on a SELECT query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

1066 error on a SELECT query

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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`
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post 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)
Post Reply