Note that DepartCountryID
and ArrivalCountryID
are two foreign keys of TravelCountryID
CREATE TABLE [dbo].[Airlines]
(
[AirlineID] [bigint] IDENTITY(1,1) NOT NULL,
[CompanyID] [int] NOT NULL,
[Code] [nvarchar](50) NOT NULL,
[DepartCountryID] [bigint] NOT NULL,
[ArrivalCountryID] [bigint] NOT NULL,
[DepartTime] [datetime] NOT NULL,
[ArrivalTime] [datetime] NOT NULL,
CREATE TABLE [dbo].[TravelCountries]
(
[TravelCountryID] [bigint] NOT NULL,
[CountryName] [nvarchar](50) NOT NULL,
This is the first select query:
SELECT
[Code], [DepartTime], [ArrivalTime], [CountryName] AS DepartCountry
FROM
[Airlines], [TravelCountries]
WHERE
[DepartCountryID] = [TravelCountryID])
Result:
1X2VC 2017-01-01 00:00:00.000 2017-01-01 03:30:00.000 Andorra
3VGH23 2018-01-10 18:45:00.000 2018-01-15 04:30:00.000 USA
The second select query:
SELECT
[Code], [DepartTime], [ArrivalTime], [CountryName] AS ArrivalCountry
FROM
[Airlines], [TravelCountries]
WHERE
[ArrivalCountryID] = [TravelCountryID])
Result:
1X2VC 2017-01-01 00:00:00.000 2017-01-01 03:30:00.000 France
3VGH23 2018-01-10 18:45:00.000 2018-01-15 04:30:00.000 England
I want the result be :
1X2VC 2017-01-01 00:00:00.000 2017-01-01 03:30:00.000 Andorra France
3VGH23 2018-01-10 18:45:00.000 2018-01-15 04:30:00.000 USA England