2
我有以下表MySQL查詢顯示成分
mysql> select * from drink;
+----+--------------+----------+---------+
| id | name | location | alcohol |
+----+--------------+----------+---------+
| 1 | Ginger Ale | 13 | 0 |
| 2 | Whiskey | 1 | 1 |
| 3 | Vodka | 2 | 1 |
| 4 | Rum | 3 | 1 |
| 5 | Gin | 4 | 1 |
| 6 | Tequila | 5 | 1 |
| 7 | Triple Sec | 6 | 1 |
| 8 | Cola | 14 | 0 |
| 10 | Cherry Vodka | 7 | 1 |
| 11 | Sprite | 15 | 0 |
| 12 | Sour Mix | 0 | 0 |
| 13 | Lemon Juice | 0 | 0 |
| 14 | Lime Juice | 0 | 0 |
| 15 | Grenadine | 0 | 0 |
| 16 | Orange Juice | 16 | 0 |
+----+--------------+----------+---------+
15 rows in set (0.00 sec)
mysql> select * from cocktail;
+----+-------+----------------------------------+
| id | name | comment |
+----+-------+----------------------------------+
| 1 | Item1 | Whiskey Ginger |
| 2 | Item2 | Screwdriver |
| 3 | Item3 | Cherry Vodka and Sprite |
| 4 | Item4 | Bartender's Long Island Iced Tea |
| 5 | Item5 | Long Island Iced Tea |
| 6 | Item6 | Gin and Sin |
+----+-------+----------------------------------+
6 rows in set (0.00 sec)
mysql> select * from mix;
+----+---------+------------+--------+
| id | drinkID | cocktailID | ounces |
+----+---------+------------+--------+
| 1 | 1 | 1 | 4.00 |
| 2 | 2 | 1 | 1.00 |
| 9 | 10 | 3 | 1.00 |
| 10 | 11 | 3 | 4.00 |
| 11 | 5 | 4 | 0.75 |
| 12 | 4 | 4 | 0.75 |
| 13 | 6 | 4 | 0.75 |
| 14 | 3 | 4 | 0.75 |
| 15 | 7 | 4 | 1.00 |
| 16 | 12 | 4 | 1.00 |
| 17 | 8 | 4 | 1.00 |
| 18 | 3 | 5 | 0.75 |
| 19 | 5 | 5 | 0.75 |
| 20 | 4 | 5 | 0.75 |
| 21 | 6 | 5 | 0.75 |
| 22 | 12 | 5 | 2.00 |
| 23 | 8 | 5 | 1.00 |
| 24 | 7 | 5 | 1.00 |
| 25 | 5 | 6 | 2.00 |
| 26 | 13 | 6 | 2.00 |
| 27 | 15 | 6 | 2.00 |
| 28 | 16 | 6 | 2.00 |
| 33 | 3 | 2 | 1.50 |
| 34 | 16 | 2 | 4.00 |
+----+---------+------------+--------+
24 rows in set (0.00 sec)
從這些表我想創建一個具有ID,評論,成分名稱,並盎司數的連接表。
到目前爲止,我有這個查詢,但我不斷收到錯誤,我不知道哪裏出錯了。
select cocktail.comment
, drink.name
, mix.ounces
from cocktail
join mix
on mix.drinkID = drink.ID
join cocktail
on mix.cocktailID = cocktail.id;
我認爲這有什麼不對我加入語句,但是在MySQL錯誤是不明確的,以我
ERROR 1066 (42000): Not unique table/alias: 'cocktail'
會有人能夠給我提供一些指導?謝謝!
你能提供表格結構嗎? –
請注意,mix table上的代理id沒有實際用途。 – Strawberry