Without its complete structure it is difficult to help you. But with the information you gave in the question, you can already find an error, you say
I have a countries table and another table with continents that have FK as the country table id
This is wrong, it is the other way around. Think the following, one country has several continents or one continent has 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 look like this:
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 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 in SQLFiddle.