Błąd zapytania sql : SELECT DISTINCT id,name,price,categoryId,manufacturerId FROM (SELECT id,name,price,0 AS position,categoryId,manufacturerId FROM product WHERE active=1 AND ( LOWER(name) LIKE '%rf%remote%control%' OR LOWER(keywords) LIKE '%rf%remote%control%' OR LOWER(searchTags) LIKE '%rf%remote%control%' OR LOWER(productCode) LIKE '%rf%remote%control%') UNION SELECT id,name,price,1 AS position,categoryId,manufacturerId FROM product WHERE active=1 AND ( LOWER(name) LIKE '%rf%control%remote%' OR LOWER(keywords) LIKE '%rf%control%remote%' OR LOWER(searchTags) LIKE '%rf%control%remote%' OR LOWER(productCode) LIKE '%rf%control%remote%') UNION SELECT id,name,price,2 AS position,categoryId,manufacturerId FROM product WHERE active=1 AND ( LOWER(name) LIKE '%remote%rf%control%' OR LOWER(keywords) LIKE '%remote%rf%control%' OR LOWER(searchTags) LIKE '%remote%rf%control%' OR LOWER(productCode) LIKE '%remote%rf%control%') UNION SELECT id,name,price,3 AS position,categoryId,manufacturerId FROM product WHERE active=1 AND ( LOWER(name) LIKE '%remote%control%rf%' OR LOWER(keywords) LIKE '%remote%control%rf%' OR LOWER(searchTags) LIKE '%remote%control%rf%' OR LOWER(productCode) LIKE '%remote%control%rf%') UNION SELECT id,name,price,4 AS position,categoryId,manufacturerId FROM product WHERE active=1 AND ( LOWER(name) LIKE '%control%rf%remote%' OR LOWER(keywords) LIKE '%control%rf%remote%' OR LOWER(searchTags) LIKE '%control%rf%remote%' OR LOWER(productCode) LIKE '%control%rf%remote%') UNION SELECT id,name,price,5 AS position,categoryId,manufacturerId FROM product WHERE active=1 AND ( LOWER(name) LIKE '%control%remote%rf%' OR LOWER(keywords) LIKE '%control%remote%rf%' OR LOWER(searchTags) LIKE '%control%remote%rf%' OR LOWER(productCode) LIKE '%control%remote%rf%') UNION SELECT id,name,price,6 AS position,categoryId,manufacturerId FROM product WHERE active=1 AND ( LOWER(name) LIKE '%rf%remote%' OR LOWER(keywords) LIKE '%rf%remote%' OR LOWER(searchTags) LIKE '%rf%remote%' OR LOWER(productCode) LIKE '%rf%remote%') UNION SELECT id,name,price,7 AS position,categoryId,manufacturerId FROM product WHERE active=1 AND ( LOWER(name) LIKE '%rf%' OR LOWER(keywords) LIKE '%rf%' OR LOWER(searchTags) LIKE '%rf%' OR LOWER(productCode) LIKE '%rf%') UNION SELECT id,name,price,8 AS position,categoryId,manufacturerId FROM product WHERE active=1 AND ( LOWER(name) LIKE '%remote%' OR LOWER(keywords) LIKE '%remote%' OR LOWER(searchTags) LIKE '%remote%' OR LOWER(productCode) LIKE '%remote%') UNION SELECT id,name,price,9 AS position,categoryId,manufacturerId FROM product WHERE active=1 AND ( LOWER(name) LIKE '%control%' OR LOWER(keywords) LIKE '%control%' OR LOWER(searchTags) LIKE '%control%' OR LOWER(productCode) LIKE '%control%')) AS t WHERE 1 ORDER BY position
Expression #1 of ORDER BY clause is not in SELECT list, references column 't.position' which is not in SELECT list; this is incompatible with DISTINCT