I am trying to run the following query:
SELECT Freight.Freight_No,
Freight.Available,
Locomotive.Loco_No,
Locomotive.Available,
Driver.Driver_No,
Driver.Name,
Driver.Available
FROM Freight,Locomotive, Driver
WHERE Freight.Available = 'Y'
AND Locomotive.Available = 'Y'
AND Driver.Available = 'Y'
GROUP BY Freight.Freight_No, Locomotive.Loco_No, Driver.Driver_No;
What I am trying to do is check available freight wagons, locomotives and drivers. I can individually run a SELECT statements. However I want to combine into one query. I understand I can do this using UNION
but I may not be going about it the correct way.
Tables
Freight
CREATE TABLE Freight
(
Freight_No integer PRIMARY KEY, Serial_No integer UNIQUE,
Freight_Wagon_Type_Name varchar(20)
REFERENCES Freight_Wagon_Type(Freight_Wagon_Type_Name),
Available varchar2(1)
CONSTRAINT AvailableFreight CHECK(Available IN('Y','N')) NOT NULL
);
Locomotive
CREATE TABLE Locomotive
(
Loco_No integer PRIMARY KEY,
Serial_No integer UNIQUE,
Loco_Class_No integer
REFERENCES Locomotive_Class(Loco_Class_No),
Loco_name varchar2(20),
Available varchar2(1)
CONSTRAINT Available CHECK(Available IN('Y','N')) NOT NULL
);
Driver
CREATE TABLE Driver
(
Driver_No integer PRIMARY KEY,
Name varchar2(20),
Available varchar2(1)
CONSTRAINT AvailableDriver CHECK(Available IN('Y','N')) NOT NULL
);
group by
you are not aggregating? You are also missing join conditions (preferrably using using standard SQL 92JOIN
s)