Mysql - Cross-table information (Selects)

Asked

Viewed 25 times

0

I am trying to make a table that presents a set of elements, where if a given id is in another table, then that element cannot be in the first.

Albums     | id1 | id2 (Foreign Key)|       

Capas| id2 |                          

Compras| id3 | id1 (Foreign Key da Tabela1)|   id4 |

Clientes| id4 |

My goal is to present the Albums, excluding those that are already associated with a particular Client.

In a way, I realized that:

select * from Albums inner join Capas using(id2);

Allow me to get everything.

and

select * from Clientes inner join Compras using(id4) inner join
Albums using(id1) inner join Capas using(id2) where id4 ='1'; 

Allows me to obtain the results for a particular Customer.

Logically I thought that to get that I would have to put together in a certain way both orders, however I have not yet achieved positive results.

If you could help me, I’d really appreciate it!!

1 answer

0

From what I understand:

SELECT * FROM 
    (Albuns INNER JOIN Capas ON (Albuns.id2 = Capas.id2)) 
    LEFT OUTER JOIN 
    (Compras INNER JOIN Clientes ON Compras.id4 = Clientes.id4) ON (Albuns.id1 = Compras.id1) 
WHERE Compras.id3 IS NULL;

What I don’t understand is where the "Inserts" of the title fits.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.