Obtain unrelated data from each other

0

I'm trying to get the data that is not related through a query between three tables, but I have not achieved the feat.

In my case I have three tables

Marcas
Categorias
Asignacion (It is the intercept table between Brands and Categories)

The relationship between brands and categories, is many to many in this case, because a brand can have several categories or lines of product, or a line of product or category, can be in several brands or be produced by several. For example

Nestle, which is a brand, can produce, cookies, chocolates, and Colombina, produces cookies and chocolates. If you look closely, both produce cookies, but one produces chocolate and the other chocolate.

So, I want to know how to obtain, in the case of selecting Nestle, obtain Chocolate, since that does not produce it, or if there are several registered in the database, obtain all the lines or categories that do not have reference to this Brand.

    
asked by Pedro Miguel Pimienta Morales 14.10.2017 в 04:30
source

2 answers

1

One way, I understand could be something like this:

SELECT C.Id_Categoria_Auto,
       C.Nombre_Categoria
       FROM Categorias C
       WHERE C.Nombre_Categoria NOT IN (SELECT  MC.Nomb_Linea
                                                FROM T_Marc_Categ MC
                                                INNER JOIN Marcas M
                                                   ON M.Nombre_Marca = MC.Nomb_Marca
                                                WHERE M.Nombre_Marca = 'NESTLE')
    
answered by 14.10.2017 в 05:57
0

By parts. First, in your explanation, you say " .... the relationship between brands and categories, is many to many in this case, because a brand can have several categories or lines of product, or a line of product or category, can be in several brands or be produced by several "

This is incorrect. Clearly, and also appears in your image, the relationship is ONE TO VARIOUS (1 to ∞). In other words, 1 brand can have infinite categories.

The second thing, to solve your problem, Access in your query assistant has an option called SEARCH FOR NON-COINCIDENTS or something like that. In summary, it allows you to extract those records that do not appear in a table.

Applied to your example, with the assistant you should be able to design a query that returns the marks that do not produce chocolate.

    
answered by 04.02.2018 в 14:38