Just at the begin of SQL and I 'm keeping stuck with this error :Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
I need to get a list of the BOM ( structure ) , but only for the last version. There last version is also NOT the main version. I just only know that it's the highest number . There are few tables involved, such : dbo.items and dbo.recipe
Tables used:
dbo.items
ID ItemCode Description
=========================================
20 KM Kilometers
19 MAA Malen
155 MAC0001 Roode Pelikaan MX3
156 MAC0002 Roode Pelikaan Carima
157 MAC0003 Roode Pelikaan Carima koppenwarmer
dbo.Recipe
ID itemprod version sequenceno itemreq quantity
=========================================
1 MCB0001 1 0 NULL 1
2 MCB0001 1 1 BON0007 1
3 MCB0001 1 2 VER0005 1
57 MCB0001 2 0 NULL 1
--For a specific item I use :
select
max(recipe.version), recipe.itemprod
from recipe
join items on items.ItemCode = recipe.itemprod
where Items.UserYesNo_02 = '1 '
group by recipe.itemprod
--to get the list of the last version number( for selected items) :
select
max(recipe.version), recipe.itemprod
from recipe
join items on items.ItemCode = recipe.itemprod
where Items.UserYesNo_02 = '1 '
group by recipe.itemprod
---Finally I try to build a script for a grouop of selected items (Items.UserYesNo_02 = '1 ' ), but this is not working... Logical error occured
select *
from recipe
join items on items.ItemCode = recipe.itemprod
where Items.UserYesNo_02 = '1 ' and recipe.itemprod in(
select
max(recipe.version), recipe.itemprod
from recipe
join items on items.ItemCode = recipe.itemprod
where Items.UserYesNo_02 = '1 '
group by recipe.itemprod