Just curious about SQL syntax. So if I have
SELECT
itemName as ItemName,
substring(itemName, 1,1) as FirstLetter,
Count(itemName)
FROM table1
GROUP BY itemName, FirstLetter
This would be incorrect because
GROUP BY itemName, FirstLetter
really should be
GROUP BY itemName, substring(itemName, 1,1)
But why can't we simply use the former for convenience?
group by
, but also tojoin
, for exampleSELECT array_agg(code) as codes, format('%s-%s', name, id) as uniqueName FROM products GROUP BY uniqueName
it complains thatname
andid
are not appearing in GROUP BY clause