Help with a join

I have two tables


create table racks (
   rack_id INT NOT NULL AUTO_INCREMENT,
   title VARCHAR(25),
...
   PRIMARY KEY ( rack_id )
);

create table devices (
   device_id INT NOT NULL AUTO_INCREMENT,
   power_distributor_id SMALLINT NULL,
   rack_id INT NOT NULL,
..
   title VARCHAR(100) NOT NULL,
...
   FOREIGN KEY (rack_id) REFERENCES racks (rack_id),
   FOREIGN KEY (power_distributor_id) REFERENCES power_distributors (power_distributor_id),
   PRIMARY KEY ( device_id )
);

which are related with a foreign key
How can I get both the title and rack_id if I know a device_id?
This is what im thinking

SELECT racks.rack_id,
               racks.title
               FROM racks
               INNER JOIN devices ON racks.rack_id = devices.rack_id
               WHERE device_id = 2;

what happened when you tested it? ™

1 Like

oh, it works (had trouble forming the JOIN)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.