I have a table called Federation
with the following fields:
IDFEDERATION--->Primary key,
FEDERATION,
PRESIDENT,
COUNTRY,
IDCOUNTRY-->Foreign Key de Country
And a table country
with the following fields:
IDCOUNTRY--->Primary key,
ENGLISHNAME,
SPANISHNAME,
LOCALNAME,
Well, what I want is to fill in the field IDCOUNTRY
with federation
the data from idcountry
the table country
, the fact is that they ask me as follows...
c) Show the UPDATE statement that will serve to populate the idCountry field of Federation. To perform said UPDATE, use a query that obtains idCountry from Country, using the country field from Federation and localName from Country.
I did this and tried something else but I can't get what is asked of me
UPDATE federation
SET federation.idcountry = (
SELECT country.idcountry
FROM country
WHERE federation.country and country.localname);
I'm a bit busy right now, I need some light.
You are not far from the solution, basically you are missing the equality condition in your query, but I would also make it a little less verbose.
In colloquial language, this would read something like: For each row of
federación
update the fieldidCountry
with the oneidCountry
in the tablecountry
for whichcountry.localname
is equal tofederation.country
.