I run the following query in SQLite Management Studio (a 2009 version) and it works fine and returns the desired result set, but when I execute from C# it gives me the following error:
No such column Q0.IntegrationItemCategoryLevelID.
It appears to be that it can't "see" the table aliases in the subqueries - I did some further tests and it can't see the other joined tables either (e.g. Q0). I tried separating it out to two queries but it absolutely killed performance. Does anyone have a good idea on how to fix this?
SELECT DISTINCT Q1.IntegrationItemCategoryLevelID, A1.ShortDesc
FROM ((_Item I
INNER JOIN (_ItemToItemCategory Q0
INNER JOIN _ItemCategory A0 ON A0.IntegrationItemCategoryID = Q0.IntegrationItemCategoryID) ON Q0.IntegrationItemID = I.IntegrationItemID)
INNER JOIN (_ItemToItemCategory Q1
INNER JOIN _ItemCategory A1 ON A1.IntegrationItemCategoryID = Q1.IntegrationItemCategoryID) ON Q1.IntegrationItemID = I.IntegrationItemID)
WHERE Q0.IntegrationItemCategoryLevelID = 14 AND A0.ShortDesc = 'LG05'
AND Q1.IntegrationItemCategoryLevelID IN (9,4,5,7,10) ORDER BY Q1.IntegrationItemCategoryLevelID
Edit: removed the extra parenthesis, same result.
SELECT DISTINCT Q1.IntegrationItemCategoryLevelID, A1.ShortDesc
FROM Item I
INNER JOIN (ItemToItemCategory Q0
INNER JOIN ItemCategory A0 ON A0.IntegrationItemCategoryID = Q0.IntegrationItemCategoryID) ON Q0.IntegrationItemID = I.IntegrationItemID
INNER JOIN (ItemToItemCategory Q1
INNER JOIN ItemCategory A1 ON A1.IntegrationItemCategoryID = Q1.IntegrationItemCategoryID) ON Q1.IntegrationItemID = I.IntegrationItemID
WHERE Q0.IntegrationItemCategoryLevelID ='14' AND A0.ShortDesc = 'LG05'
AND Q1.IntegrationItemCategoryLevelID IN (9,4,5,7,10) ORDER BY Q1.IntegrationItemCategoryLevelID
SELECT sqlite_version();)