Return data from an N:N table only with foreign keys

Asked

Viewed 202 times

0

Good afternoon, I am inciante in SQL language, and I’m wondering how to return the values of foreign keys in a relation N:N example, return the product name and the part name. Grateful from now on.

tabelas

  • Select p.product name_parts from product p Inner Join lista_p lp on p.idProduct = lp.idProduct Inner Join Parts pp on lp.idPeças = pp.idPeças

  • 1

    Thanks Marconi, I made some changes and it worked!! vlw =)

  • Glad I could help Deltman, welcome to stackoverflow. It’s interesting to read on tour to find out how things work around here. I recommend reading this post: What is the difference between INNER JOIN and OUTER JOIN?, will give you a more detailed overview of queries.

  • 1

    Thanks for the tips, I will read yes =).

1 answer

0

I believe you can wear something like this:

select lp.idProduto,  pd.nome_produto, lp.[idPeças] , pc.[nome_peça]
from [lista_peça] lp inner join produto pd on pd.idProduto = lp.idProduto
inner join [Peças] pc on pc.[idPeças] = lp.[idPeças]

But I strongly advise you not to use special characters in tables and fields.

Abs.

Browser other questions tagged

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