I’ve a table with values like:
row item_id device_token
1 1 1234
2 2 2345
3 1
4 2
5 1
6 1 1234
I would like to select all values, but group them by item_id and device_token.
SELECT item_id, device_token FROM hits GROUP BY item_id, device_token
Grouping the above data would results in 4 rows, as row 1,6 and 3,5 would be combined. Can I make a query which does not group the rows where the device_token is empty/null (row 3 and 5)?
If you don’t want the rows where device_token is empty this is easy – just use a simple
WHEREclause as others have suggested.And if you want to have both, those with matching device_token grouped and those without a device token as single rows, you can combine two queries with a
UNION: