S
S
Sergey Zolotarev2020-11-01 12:02:17
SQL
Sergey Zolotarev, 2020-11-01 12:02:17

How to display unique product properties by category ID using SQL query?

Now I'm solving the last problem in the SQL and database test, which talks about a database that has 4 tables:

  • table of product categories category (id, name);
  • product table product (id,category_id,name,price);
  • property table property (id, name);
  • table of goods property values ​​property_value (product_id,property_id,value);

And the problem lies in the condition itself:

Get a list of names of unique product properties by category name (the property should be only for 1 product in the category)

This is the first time I have encountered such a task of this kind (have you ever encountered this?) and I want to deal with an SQL query that allows you to get a unique list of product properties by category ID. Since I have about a year of experience with SQL, I did not play around with more complex queries. Do you have a variant of such a query, while using SELECT DISTINCT, so that I can write it as an answer?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Tsvetkov, 2020-11-01
@yellow79

Well, here it turns out you need to get all the properties of goods for a particular category, count their number, grouping them by property id first, and then take only those where the number is equal to one. Looks simple enough. But maybe I misunderstood the problem statement.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question