New answers tagged

0 votes

Using GROUP BY together with wildcards for table columns

select distinct p.product_id, i.filename, pp.* "select distinct" is a Big Red Flag for me. select distinct a, b, c can perform as badly as select a, b, c group by a, b, c order by a, b, c! ...
user avatar
  • 6,469
-1 votes

Using GROUP BY together with wildcards for table columns

You can use GROUP BY with wildcards if you include primary keys into GROUP BY list. Added in 9.1 https://www.postgresql.org/docs/9.1/release-9-1.html#AEN110817.
user avatar
0 votes

Postgresql - how to use bool_and with group by

As @a_horse_with_no_name indicated in their comment, the syntax is correct. The query failed for me due to some issues with the client I used.
user avatar
  • 147
-1 votes

How to Join two tables with SUM and GROUP BY in SQL server

SELECT Designation, SUM(Qty) FROM Product P JOIN sub_product Q ON Q.Product_ID = P.id GROUP BY Designation ORDER BY Designation ? downvoted? LOL DECLARE @Product TABLE (ID INT, Designation VARCHAR(10)...
user avatar
  • 333
3 votes
Accepted

How to Join two tables with SUM and GROUP BY in SQL server

This can be accomplished simply with a JOIN and GROUP_BY clause like so: SELECT p.designation, SUM(ISNULL(sp.quantity, 0)) AS [total quantity] FROM product AS p LEFT JOIN sub_product AS sp ...
user avatar
  • 24.1k

Top 50 recent answers are included