T
T
tempman2017-06-14 14:12:58
MySQL
tempman, 2017-06-14 14:12:58

Which SQL-select: MySQl one-to-many select with join?

Help with SQL query:
Task:
There is a table (id, product_id, data) with a one-to-many relationship, i.e. tovar_id can have several data values, where each value is written as a separate record . Do the following
:
Make a selection - display a list of tovar_id, where SIMULTANEOUSLY there are several different data values ​​(according to the list). Those. not a list of all records for each occurrence of the data value, but a list of tovar_id, where ALL listed data values ​​are found SIMULTANEOUSLY
. you don’t need data 6 or 7 separately, but only those product_id, where there is an entry for both data 6 and data 7, i.e. don't show tovar_id, where there is data 6, but not data 7
How to make a query correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2017-06-14
@tempman

SELECT A.tovar_id FROM `таблица` AS A
                  JOIN `таблица` AS B
    ON A.tovar_id = B.tovar_id
    WHERE A.data = "data6" AND B.data = "data7";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question