MySQL Group By And Skip Grouping On Null Values
select * from dc_deal group by collection_id In collection_id column i have values (1,3,3,4,4,5,NULL,NULL) . Above query will return rows with (1,2,3,4,NULL) but i want to skip grouping on NULL value and need result like (1,2,3,4,NULL,NULL) If we have a unique column (or set of columns) in the table, then we can add another expression to the GROUP BY . The expression needs to return a unique value for each row when collection_id is null. Otherwise, it returns a constant. Assuming we have a unique id column in the table, then we can do something like this: ... GROUP BY collection_id, IF