MySQL returns fewer rows with GROUP BY statement
- by bschaeffer
I've got a MySQL database that stores image information. Right now it only has three rows stored in the database, and each row is associated with something like, for instance, a unique blog post via a key column.
As of right now, one "blog post key" has one image, and one has two images in the database.
When I run this query, MySQL returns all three rows.
SELECT `id`, `key`, `url`
FROM (`images`)
WHERE `key` = 'TpaS4G5h'
OR `key` = '78855e44'
However, when i add the GROUP BY statement I only get two rows... one for each key.
SELECT `id`, `key`, `url`
FROM (`images`)
WHERE `key` = 'TpaS4G5h'
OR `key` = '78855e44'
GROUP BY `key`
I'm sure there is a simple solution, but I don't know what it is... so any help would be really appreciated.
Thanks in advance!