I have a table like this
--------------------
| color | date |
--------------------
| red | 01/01/10 |
| blue | 01/07/10 |
| ... |
I want to select the maximum date of every type. The easy way has (realy) bad performance. ie:
SELECT color, MAX(date)
FROM myTable
WHERE color = ANY(ARRAY('red', 'blue'))
GROUP BY date;
What has good performance the following query. I think this is because of the index on date.
SELECT color, date
FROM myTable
WHERE color='red'
ORDER BY date
LIMIT 1
the problem is that I do not have the same result. I would like to find a way to use the 2nd version to have the same result as the first query.
Perhaps I could use a Loop and select the union of each result. Is this even possible?
Any other idea is welcomed?
IN(ARRAY('red', 'blue')has multiple serious problem, please update your question to include your real queries.