I'm using the world database in SQL server 2016, and I have a little doubt, I'm practicing and one of the questions is to select the countries and their respective capitals, my problem is that in cities I have 5 or 6 country, and I do not know how to make me select only the capital.
select c.Name, p.Name, c.Code from country as c
inner join city as p on c.Code = p.CountryCode
is what has occurred to me so far, I appreciate your suggestions.
The tables are structured like this:
CREATE TABLE city (
ID int NOT NULL,
Name char(35) NOT NULL DEFAULT '',
CountryCode char(3) NOT NULL DEFAULT '',
District char(20) NOT NULL DEFAULT '',
Population int NOT NULL DEFAULT '0',
PRIMARY KEY (ID)
)
CREATE TABLE country (
Code char(3) NOT NULL DEFAULT '',
Name char(52) NOT NULL DEFAULT '',
Continent varchar(20) CHECK(Continent in ('Asia','Europe','North
America','Africa','Oceania','Antarctica','South America')) NOT NULL
DEFAULT 'Asia',
Region char(26) NOT NULL DEFAULT '',
SurfaceArea decimal(10,2) NOT NULL DEFAULT '0.00',
IndepYear smallint DEFAULT NULL,
Population int NOT NULL DEFAULT '0',
LifeExpectancy decimal(3,1) DEFAULT NULL,
GNP decimal(10,2) DEFAULT NULL,
GNPOld decimal(10,2) DEFAULT NULL,
LocalName char(45) NOT NULL DEFAULT '',
GovernmentForm char(45) NOT NULL DEFAULT '',
HeadOfState char(60) DEFAULT NULL,
Capital int DEFAULT NULL,
Code2 char(2) NOT NULL DEFAULT '',
PRIMARY KEY (Code)
)