Reputation: 452
I have two tables.
Goods:
Table "public.goods"
Column | Type | Modifiers
-----------------+--------------------------+---------------------------
goods_id | character varying | not null
goods_owner_id | character varying | not null
Sellers:
Table "public.sellers"
Column | Type | Modifiers
-----------------+--------------------------+---------------------------
sellers_id | character varying | not null
sellers_name | character varying | not null
How to make a request that will show sellers with the most quantity of goods? Thank you.
Upvotes: 0
Views: 28
Reputation: 5573
Here is sql query:
SELECT sellers.sellers_id
FROM goods JOIN sellers ON goods.goods_owner_id = sellers.sellers_id
GROUP BY sellers.sellers_id
ORDER BY COUNT(goods.goods_id) DESC
LIMIT 1
Upvotes: 1