INNER JOIN выпуск - PullRequest
       36

INNER JOIN выпуск

0 голосов
/ 24 февраля 2011

Я получаю следующую ошибку из этого запроса:

1054 - Неизвестный столбец 'sheet_items.color_id' в 'предложении'

select sheet_items.sheet_id, sheet_items.quantity, materials.material, colors.color
from sheet_items, materials
inner join colors
on colors.color_id=sheet_items.color_id
where sheet_items.sheet_id=4 and sheet_items.material_id=materials.material_id

Есть идеи? Заранее спасибо!

Ответы [ 4 ]

1 голос
/ 24 февраля 2011

Похоже, ваше микширование до и после SQL ANSI92, попробуйте либо ...

PRE ANSI92

select sheet_items.sheet_id, sheet_items.quantity, materials.material, colors.color
from sheet_items, materials, colors
where sheet_items.sheet_id=4 and sheet_items.material_id=materials.material_id AND
colors.color_id=sheet_items.color_id

POST ANSI92

select sheet_items.sheet_id, sheet_items.quantity, materials.material, colors.color
from sheet_items
inner join materials
on sheet_items.material_id=materials.material_id
inner join colors
on colors.color_id=sheet_items.color_id
where sheet_items.sheet_id=4

В любом случае ИМХОВторой формат легче читать / понимать и отлаживать, и он будет работать на всех платформах SQL

1 голос
/ 24 февраля 2011

Как вы сейчас это структурировали, вы пытаетесь объединить материалы с цветами, поэтому он не знает, о каком столбце вы говорите .. попробуйте

select sheet_items.sheet_id, sheet_items.quantity, materials.material, colors.color
from materials,sheet_items
inner join colors
on colors.color_id=sheet_items.color_id
where sheet_items.sheet_id=4 and sheet_items.material_id=materials.material_id
0 голосов
/ 24 февраля 2011

Не путайте то, как вы присоединяетесь, это очень сбивает с толку.

SELECT sheet_items.sheet_id, sheet_items.quantity, materials.material, colors.color
FROM
sheet_items
INNER JOIN materials ON materials.id=sheet_items.material_id
INNER JOIN colors ON colors.color_id=sheet_items.color_id
WHERE
sheet_items.sheet_id=4
0 голосов
/ 24 февраля 2011

У вас есть неявное внутреннее соединение в предложении where между sheet_items и материалами.Вы должны извлечь это из предложения where и вставить в проекцию, чтобы оно выглядело так:

select sheet_items.sheet_id, sheet_items.quantity, materials.material, colors.color from materials
inner join sheet_items on materials.material_id=sheet_items.material_id 
inner join colors on colors.color_id=sheet_items.color_id 
where sheet_items.sheet_id=4
...