A
A
Alexey Popov2020-01-11 17:51:03
SQL
Alexey Popov, 2020-01-11 17:51:03

Get a limited number of id for each characteristic through the logical IN operator or in some other way?

In general, there is such a table structure
5e19de17bc969895442410.png
. This table stores the values ​​of the characteristics of goods.
Can I somehow get a limited number of values ​​for each characteristic with this code?

SELECT * from `table_name` WHERE `feature_id` IN (90,91,92,93...)

At the moment, such a query will give me all the values ​​of each characteristic that is placed in the IN operator, and this is logical. Is it possible to somehow remake this query so that for each characteristic I would not receive all the values, but only 6 for example?
I do not rule out that a working request that will satisfy my conditions will be without an IN operator at all. The main thing is that you do not want to produce a "SELECT" query for each characteristic, but take this data with one query.
I hope I explained the problem clearly :)
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2020-01-11
@AlexWinter

(
  SELECT ...
    FROM `table`
    WHERE `feature_id` = 90
    LIMIT 6
) UNION (
  SELECT ...
    FROM `table`
    WHERE `feature_id` = 91
    LIMIT 6
) UNION ...

K
Konstantin Tsvetkov, 2020-01-11
@tsklab

Subquery with LIMIT 6.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question