MySQL and UUID problem
I have a database where I am trying to group together similar column values and display the NULL values as separate entries.
Currently I have the following:
SELECT i.*, IFNULL(iset.set_id, UUID()) AS the_set FROM img_ref i
LEFT JOIN image_set iset ON iset.img_id = i.id
GROUP BY the_set
This works, provided there are entries in the image_set table. If there are no entries in that table, it simply groups together all the NULL values. If I remove the开发者_如何学编程 'group by' statement, I get the individual rows with the unique identifier, different in each case.
Its unlikely that the image_set table would be empty, but if it was all the 'separate' images would be grouped together as one entry instead of multiple ones.
Is there something that I'm doing wrong in the query?
You have to subquery it first before using the derived UUIDs
SELECT *
FROM (
SELECT i.*, IFNULL(iset.set_id, UUID()) AS the_set FROM img_ref i
LEFT JOIN image_set iset ON iset.img_id = i.id
) SQ
GROUP BY the_set
精彩评论