I have a JPA query structured like this:
SELECT distinct item
FROM ...
WHERE ...
ORDER BY ...
I'm using MySQL 8 and because I'm using the ORDER BY clause to sort by item properties, area name country name and brand name) I was getting this error:
Expression #1 of ORDER BY clause is not in SELECT list, references column 'db.country4_.name' which is not in SELECT list; this is incompatible with DISTINCT
I had to include the order by fields in the SELECT:
SELECT distinct item, item.area.name, item.country.name, item.brand.name
FROM ...
WHERE ...
ORDER BY ...
The problem is that doing so the query now doesn't select anymore the items that have country == NULL.
Beside removing the distinct or changing the sql-mode
?
Thanks