Ricardo Goncalves
Ricardo Goncalves

Reputation: 3

Grouping records from one table into one

enter image description here

Basically, I'm trying to retrieve only 1 record from a table based on catalog_no and packing_list_no. However, the table I'm retrieving the information from has additional details that I don't need but makes the 1 record I need into 3 distinct records.

I tried summing and grouping the info, but I'm still getting 3 records instead of 1.

Any ideas of how to solve this issue?

Upvotes: 0

Views: 39

Answers (1)

JoPapou13
JoPapou13

Reputation: 773

Your GROUP BY groups your result on the columns quantity picked, quantity shipped and weight shipped. A different value in any of those columns will result into a different row.

You can drop the GROUP BY clause all together, if the desirable result is the packing list and catalog no that you have specified. You can use the GROUP BY clause to columns that you do not use sum to group the result set.

SELECT catalog_no, sum(qty_picked), sum(qty_shipped), sum(weight_shipped), packing_list_no, bay_no, carrier_code, tracking_no FROM oeorder_shipping
WHERE packing_list_no='CP12618525' AND catalog_no='437656500'
GROUP BY bay_no, carrier_code, tracking_no;

Upvotes: 1

Related Questions