Maybe something like this:
SELECT t.id, t.KEY, t.VALUE, t.col1, t.col2, t.col3, t.col4, t.col5
FROM TABLE t INNER JOIN (SELECT MIN(a.id) id
FROM TABLE a INNER JOIN TABLE b ON (a.KEY=b.KEY)
WHERE a.value<>b.VALUE
GROUP BY a.KEY, a.VALUE) x ON (t.id=x.id)
WHERE t.col1='color' AND (t.col3 LIKE '%text%' OR t.col5 IN (1, 3, 5))
ORDER BY t.KEY, t.VALUE
Thank you, it's a big help for me. Seems to me its works better, but not perfect yet. For example:
SELECT t.ID, t.TYPE, t.Age, t.KeyName, t.KeyValue
FROM main t
INNER JOIN (SELECT MIN(a.ID) ID
FROM main a
INNER JOIN main b ON (a.KeyName=b.KeyName)
WHERE a.KeyValue<>b.KeyValue
GROUP BY a.KeyName, a.KeyValue) x ON (t.ID=x.ID)
WHERE (t.TYPE='To') AND (t.Age="Last") ORDER BY t.KeyName, t.KeyValue;
In this query tAge has 3 possible value, but these command can find only two values of them (1 missing). In DB browser/browse data page I can found all values with above conditions.
Perhaps this line "a.KeyValue<>b.KeyValue" confuse logic.
Second, in the first line I can't access to a, b, or X.KeyValue (to see them).
Anyway, as I see, I will use more tables of the easy and exact select... but thank you again for this SQL Pro codes!