Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to link 4 tables using an mySQL query
    primarykey
    data
    text
    <p>Vehicle</p> <pre><code>+--------------------+--------------+------+-----+---------+ | Field | Type | Null | Key | Default | +--------------------+--------------+------+-----+---------+ | id | int(11) | NO | Pk | NULL | | model | varchar(35) | NO | | NULL | +--------------------+--------------+------+-----+---------+ </code></pre> <p>info</p> <pre><code>+--------------------+--------------+------+-----+---------+ | Field | Type | Null | Key | Default | +--------------------+--------------+------+-----+---------+ | id | int(11) | NO | Pk | NULL | | vehicle_id | varchar(35) | NO | FK | NULL | | location | varchar(35) | NO | | NULL | +--------------------+--------------+------+-----+---------+ </code></pre> <p>Axle 1</p> <pre><code>+--------------------+--------------+------+-----+---------+ | Field | Type | Null | Key | Default | +--------------------+--------------+------+-----+---------+ | id | int(11) | NO | Pk | NULL | | vehicle_id | varchar(35) | NO | FK | NULL | | weight | varchar(35) | NO | | NULL | +--------------------+--------------+------+-----+---------+ </code></pre> <p>Axle 2</p> <pre><code>+--------------------+--------------+------+-----+---------+ | Field | Type | Null | Key | Default | +--------------------+--------------+------+-----+---------+ | id | int(11) | NO | Pk | NULL | | vehicle_id | varchar(35) | NO | FK | NULL | | weight | varchar(35) | NO | | NULL | +--------------------+--------------+------+-----+---------+ </code></pre> <p>I wish to create a query that will return all the fields from all tables with a common vehicle_id. The vehicle_id being a reference in each of the 3 tables (info, axle1, axle 2) to the primary key in the Vehicle table. Could someone please explain how I might go about doing so? I tried using multiple joins but it didnt work!Many thanks.</p> <p>EDIT: </p> <p>Query I tried was;</p> <pre><code>SELECT * FROM Vehicle JOIN info, axle1, axle 2 ON vehicle.id = axle1.vehicle_id AND vehicle.id = axle2.vehicle_id AND vehicle.id = info.vehicle_id </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload