Back to Yugabyte Db

GROUP BY

community/learn/content/01-SQL-Basics/02-fundamentals/11-group-by.md

2026.1.0.0-b29658 B
Original Source

SELECT with a GROUP BY

In this exercise we will query the products table and group the results by product_id, then product_name, and finally unit_price.

SELECT product_id,
       product_name,
       unit_price
FROM products
GROUP BY product_id,
         product_name,
         unit_price;

This query should return 77 rows

SELECT with a GROUP BY and a function

In this exercise we will query the orders table and group the results by employee_id, while only returning the total counts of order_id.

SELECT count(order_id),
       employee_id
FROM orders
GROUP BY employee_id;

This query should return 9 rows