TEC_DOC запрос на аналоги ART LOOKUP2.sql

kolyan2288
Дата: 22.10.2015 13:11:35
Привет всем, делаю запросы как по документации
[url=]http://manual.mstarproject.com/index.php/Документация_по_запросам_и_структуре_Текдок_-_версия_2[/url]

Вообщем не работает запрос
SELECT DISTINCT
IF (ART_LOOKUP2.ARL_KIND = 3, BRANDS2.BRA_BRAND, SUPPLIERS2.SUP_BRAND) AS BRAND,
IF (ART_LOOKUP2.ARL_KIND IN (2, 3), ART_LOOKUP2.ARL_DISPLAY_NR, ARTICLES2.ART_ARTICLE_NR) AS NUMBER,
ART_LOOKUP2.ARL_KIND
FROM          ART_LOOKUP
LEFT JOIN BRANDS ON BRANDS.BRA_ID = ART_LOOKUP.ARL_BRA_ID
INNER JOIN ARTICLES ON ARTICLES.ART_ID = ART_LOOKUP.ARL_ART_ID
INNER JOIN SUPPLIERS ON SUPPLIERS.SUP_ID = ARTICLES.ART_SUP_ID
INNER JOIN ART_LOOKUP AS ART_LOOKUP2 FORCE KEY (PRIMARY) ON ART_LOOKUP2.ARL_ART_ID = ART_LOOKUP.ARL_ART_ID
LEFT JOIN BRANDS AS BRANDS2 ON BRANDS2.BRA_ID = ART_LOOKUP2.ARL_BRA_ID
INNER JOIN ARTICLES AS ARTICLES2 ON ARTICLES2.ART_ID = ART_LOOKUP2.ARL_ART_ID
INNER JOIN SUPPLIERS AS SUPPLIERS2 FORCE KEY (PRIMARY) ON SUPPLIERS2.SUP_ID = ARTICLES2.ART_SUP_ID
WHERE
ART_LOOKUP.ARL_SEARCH_NUMBER = @NUMBER AND
(ART_LOOKUP.ARL_KIND IN (3, 4) AND BRANDS.BRA_BRAND = @BRAND OR  SUPPLIERS.SUP_BRAND = @BRAND) AND
(ART_LOOKUP.ARL_KIND, ART_LOOKUP2.ARL_KIND) IN	((1, 1), (1, 2), (1, 3),(2, 1), (2, 2), (2, 3),(3, 1), (3, 2), (3, 3), (4, 1))
ORDER BY BRAND, NUMBER;


Ошибка на строку:
INNER JOIN ART_LOOKUP AS ART_LOOKUP2 FORCE KEY (PRIMARY) ON ART_LOOKUP2.ARL_ART_ID = ART_LOOKUP.ARL_ART_ID

но поле ARL_ART_ID я не могу установить PRIMARY т. к. есть одинаковые записи.
Кто сталкивался скажите как вы прошли мимо этой проблемы? спасибо