Skip to content
Advertisement

SQL get total sellers of product category

I have like this database tables:

Table categories

Table products

Table product_varieties

I have query to get price min, max and avg in each category:

Now I need get total users (sellers) of each category by editing my current query.

I tried like this:

But my query not work and return error with message:

How I can correct my query?

Advertisement

Answer

A “correlated subquery” can be used in the select list of your main query, this query must return just a single value and the “correlation” occurs through the where clause in that some data from the main query is used to locate the wanted data in the subquery.

but I suspect this can be further simplified:

or, depending on the data:

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