0

私は mysql を学んでいますが、#1066 を生成するテーブルの 1 つで問題が発生しています - エラーが一意のテーブル エイリアスではありません。さまざまなクエリを試しましたが、すべて同じ結果になりました。誰かが私を悲惨な状態から解放し、私が間違っていることを指摘してくれませんか! - ありがとう

テーブル

looks
---------

look_id(Pk)
user_id
title
description
date_modified

Add_Look_Item
-----------------------

look_id (fk from table 1)
item_id (fk from table 3)

Item
--------------

item_id (pk)
name
details

Add_Images
-------------------
image_id (pk)
item_id (fk from table 3)
image_name

私が試したクエリ - add_look_item は複合キーです

SELECT DISTINCT looks.look_id, looks.title, looks.date_modified, add_look_item.item_id,     add_images.image_name FROM looks JOIN add_look_item ON add_look_item.look_id = looks.look_id
JOIN add_look_item ON add_look_item.item_id = item.item_id WHERE look.user_id = 94

#1066 - error not unique table alias 'add_look_item

SELECT DISTINCT looks.look_id, looks.title, looks.date_modified, add_look_item.item_id,     add_images.image_name FROM looks JOIN 
add_look_item ON add_look_item.looks_id = look.look_id
JOIN add_look_item ON add_look_item.item_id = item.item_id
JOIN add_images ON add_images.item_id = item.item_id WHERE add_look_item.item_id =    item.item_id AND look.user_id = 94

#1066 - error not unique table alias 'add_look_item

SELECT DISTINCT looks.look_id, looks.title, looks.date_modified, add_look_item.item_id,   add_images.image_name FROM looks INNER JOIN add_look_item ON add_look_item.look_id =    look_look_id
INNER JOIN add_images ON add_images.item_id = item.item_id
INNER JOIN add_look_item ON add_look_item.item_id = item.item_id
WHERE look.user_id = 94

#1066 - error not unique table alias 'add_look_item

SELECT DISTINCT looks.look_id, looks.title, looks.date_modified, add_look_item.item_id,    add_images.image_name FROM looks 
INNER JOIN add_look_item ON add_look_item.looks_id = look.look_id
INNER JOIN add_images ON add_images.item_id = item.item_id
INNER JOIN add_look_item ON add_look_item.item_id = item.item_id 
WHERE add_look_item.item_id = item.item_id AND look.user_id = 94


#1066 - error not unique table alias 'add_look_item

SELECT DISTINCT looks.look_id, looks.title, looks.date_modified, add_look_item.item_id,    add_images.image_name FROM looks 
INNER JOIN add_look_item ON add_look_item.looks_id = look.look_id
INNER JOIN add_images ON add_images.item_id = item.item_id
WHERE add_look_item.item_id = item.item_id AND look.user_id = 94

#1054 - Unknown column 'item.item_id' in 'where clause'

ありがとう

4

2 に答える 2

1

これを試して -

SELECT looks.look_id, looks.title, looks.date_modified, add_look_item.item_id, add_images.image_name
FROM looks
JOIN add_look_item
    ON looks.look_id = add_look_item.look_id
JOIN add_images
    ON add_look_item.item_id = add_images.item_id
WHERE look.user_id = 94
于 2012-04-06T10:16:07.683 に答える
1

複数回参加するので、add_look_item のエイリアスを作成します。

例えば:

SELECT tbl.a, a.y, b.y 
FROM tbl 
JOIN tbl2 as a ON tbl.x = a.x 
JOIN tbl2 as b ON tbl.x = b.x

そうしないと、クエリエンジンは何をすべきかわかりません:)

于 2012-04-06T10:02:31.777 に答える