For example, I have the following tables:
pilot(eID, pID)
plane(pID, make, model, range)
(eID means employee ID and pID means planeID)
I want to get the eID of the pilot and the model of the plane the pilot flys, of all the planes made by Airbus. It seems there are multiple ways to get this, and I'm not sure which should be used:
using natural join:
SELECT pilot.eID, plane.model FROM pilot NATURAL JOIN plane WHERE plane.make = 'Airbus'
using cross join: (or the equivalent where you replace pilot, plane
with pilot CROSS JOIN plane
)
SELECT pilot.eID, plane.model FROM pilot, plane WHERE pilot.pID = plane.pID AND plane.make = 'Airbus'
using theta join:
SELECT pilot.eID, plane.model FROM pilot join plane ON pilot.pID = plane.pID WHERE plane.make = 'Airbus'
(I understand you can use USING (pID)
instead of on pilot.pID = plane.pID
for theta join and it will remove the duplicate pID column).
Which is the better to use? Why are there these different ways of doing it? (As in what other cases would there be that required one query rather than the others) And if I didn't have the make = 'Airbus'
requirement would the answer be different?