Without its complete structure it is difficult to help you. But with the information you gave in the question, you can already find a mistake, you say
I have a countries table and another table with continents having as FK the id of the countries table
This is wrong, it is the other way around. Think about this, does a country have several continents or does a continent have several countries? Obviously a continent that has several countries, so the countries that are inserted in the continent and not the other way around.
Your tables need to stay that way:
CONTINENTES PAISES
---------------------------------------
ID (PK) ID (PK)
DESCRICAO DESCRICAO
ID_CONTINENTE (FK)
And to bring all the countries of a continent, it is necessary to make a select
using inner join
. See more about the inner join
here.
SELECT P.DESCRICAO FROM PAISES P
INNER JOIN CONTINENTES C ON C.ID = P.ID_CONTINENTE
WHERE C.ID = 1
See working on Sqlfiddle.
You can edit your question with the table structure?
– Giancarlo Abel Giulian
Without the table structure is kind of complicated, enjoy and create a sqlfiddle.
– rray
Did you manage? I was making a sqlfiddle, but if you have already I will not finish
– Jéf Bueno
I thought I did, but no. I updated with my tables
– daniel12345smith
See my Sqlfiddle, you will have to change your tables.
– Jéf Bueno