I’m working on SQL right now and I’ve got these tables:
CREATE TABLE Gym (
eid INT PRIMARY KEY,
name VARCHAR(127) UNIQUE,
district VARCHAR(127),
area INT);
CREATE TABLE Trainer (
id INT PRIMARY KEY,
name VARCHAR(127),
birth_year INT,
year_credentials_expiry INT
);
CREATE TABLE Works (
eid INT,
id INT,
since INT,
FOREIGN KEY (eid) REFERENCES Gym (eid),
FOREIGN KEY (id) REFERENCES Trainer (id),
PRIMARY KEY (eid,id));
I want to build a query that can tell me the names of the gyms with the district ‘Casanova’ where, at least, there is a trainer working.
I’ve been thinking about using the EXISTS operator but there must be a simpler method.
CAn anybody help me?
A simple
INNER JOINbetweenGymandWorkstable will do:If there isn’t at least one trainer working in that Gym, this query would return nothing.