Answer the question
In order to leave comments, you need to log in
How to make a SQL query on three tables?
You need to select products that have ALL possible tags from the database. In this case, the answer should be Bread. On sqlite
Base example
CREATE TABLE product (id INTEGER, name TEXT);
INSERT INTO product (id, name)
VALUES
(1, 'Beer'),
(2, 'Bread'),
(3, 'Chease'),
(4, 'Water');
CREATE TABLE labels (id INTEGER, name TEXT);
INSERT INTO labels (id, name)
VALUES
(1, 'Nice'),
(2, 'Bad'),
(3, 'Normal'),
(4, 'Lol');
CREATE TABLE labels_products (label_id INTEGER, product_id INTEGER, UNIQUE (label_id, product_id));
INSERT INTO labels_products (label_id, product_id)
VALUES
(1, 1),
(2, 1),
(3, 1),
(4, 1),
(1, 3),
(2, 2),
(3, 3);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question