D
D
Dark_Dante2016-11-16 10:37:42
MySQL
Dark_Dante, 2016-11-16 10:37:42

How to print the difference between two queries?

Hello.
There are three tables. Table A, table B and table C
VpYBILF.png
A - goods, B - brands, C - suppliers
Field a.id_brand is associated with B. id
Table C and table B have the same id for identical manufacturers.
I need to select only those products that have a brand but no supplier.
That is, in this case, in the picture, only the product with ID = 5 - 5 - MMM - Reebok
As I understand it, you need to "subtract" tables B from table C and select only those products where id_brand is present in the "difference" of two tables.
Only I don’t understand something, how to do it in SQL
Please tell me =(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2016-11-16
@Dark_Dante

But if the vendor name is the same as the brand name, then brand id == vendor id

somehow this is not correct, but for your case you can do this
SELECT a.id, a.article, a.brand_id FROM a
INNER JOIN b on a.brand_id = b.id
LEFT JOIN c ON b.name = c.name
WHERE c.id IS NULL

M
Max, 2016-11-16
@MaxDukov

read about LEFT JOIN/ RIGHT JOIN.
in this case, you need to do a LEFT JOIN A and B, and RIGHT JOIN c C to them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question