0

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.

2
  • Does public.goods table has foreign key constraint that references sellers_id column of public.sellers? Commented Apr 25, 2018 at 20:29
  • There are no such restrictions. Commented Apr 26, 2018 at 4:32

1 Answer 1

1

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 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.