Answering your question:
What you want is not subselect but rather JOIN
.
Example of JOIN
whereas your sale table will always have 1 book referring to the sale:
SELECT *
FROM VENDAS VD
INNER JOIN LIVROS LV ON LV.IDLIVRO = VD.IDLIVRO
Filtering some fields:
SELECT VD.IDVENDA, LV.TITULO, LV.PRECO
FROM VENDAS VD
JOIN LIVROS LV ON LV.IDLIVRO = VD.IDLIVRO
>
Extra examples:
In order to bring ALL values of the table INNER JOIN
even though did not have filled in the JOIN
field in the% JOIN
:
SELECT *
FROM VENDAS VD
LEFT JOIN LIVROS LV ON LV.IDLIVRO = VD.IDLIVRO
In order to bring ALL values of the table INNER
even though did not have filled in the VENDAS
field in the% IDLIVRO
:
SELECT *
FROM VENDAS VD
RIGHT JOIN LIVROS LV ON LV.IDLIVRO = VD.IDLIVRO
Reference to VENDAS
that would be nice to see as an example:
Select only tuples from a table with JOIN