JOINing two tables

#1

I have 2 tables,

create table racks (
   rack_id INT NOT NULL AUTO_INCREMENT,
   location VARCHAR(100) NOT NULL,
   elevation VARCHAR(100) NULL,
   title VARCHAR(100) NOT NULL,
   power_panel VARCHAR(100) NOT NULL,
   circuit_breaker VARCHAR(10) NOT NULL,
   number_of_slots INT NOT NULL,
   display CHAR(1) DEFAULT '1',
   PRIMARY KEY ( rack_id )
);

create table devices (
   device_id INT NOT NULL AUTO_INCREMENT,
   rack_id INT NOT NULL,
   orientation CHAR(1) DEFAULT '1',
   beginning_slot DECIMAL(3,1) NOT NULL,
   ending_slot DECIMAL(3,1) NOT NULL,
   device VARCHAR(100) NOT NULL,
   width INT DEFAULT NULL,
   beginning_x INT DEFAULT NULL,
   display CHAR(1) DEFAULT '1',
   updated_by VARCHAR(25) DEFAULT 'Luke Utnoski',
   updated_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   FOREIGN KEY ( rack_id ) REFERENCES racks (rack_id),
   PRIMARY KEY ( device_id )
);

Im running this query

SELECT rack_id, device_id, orientation, device, beginning_slot, ending_slot, beginning_x, width, updated_by, updated_date, display FROM devices';

the result


How do I alter the quert to showthe titlein the rack table instead of the rack_id?

#2

with a join

SELECT racks.title
     , devices.device_id
     , devices.orientation
     , devices.device
     , devices.beginning_slot
     , devices.ending_slot
     , devices.beginning_x
     , devices.width
     , devices.updated_by
     , devices.updated_date
     , devices.display 
  FROM racks
INNER
  JOIN devices
    ON devices.rack_id = racks.rack_id
1 Like