Skip to content
Advertisement

Finding max count of product

I am trying to find max count of product. The result must only display the brands which have max number of products in it. Can anyone suggest a better way to display result.

Here are the table details:

I have used this SQL query below but I am seeing an error below. The result must display the list of the brands that have max number of products as compared to other brands.

ERROR: aggregate functions are not allowed in WHERE LINE 2: where count(p.id) = (select max(count) from product) ^ SQL state: 42803 Character: 105

Advertisement

Answer

In Postgres 13+, you can use FETCH WITH TIES:

In older versions you can use window functions.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement