jrm jrm - 2 months ago 9
MySQL Question

linking 2 mysql tables thanks to a third liaison table

I have 3 tables:


  1. img : id, name

  2. fig : id, x, y, z

  3. link : id, imgid, figid



I use the 'link' table to connect certain img ids to certain fig ids (I hope it's clear)

Question: I am struggling to find the correct SQL query to find "all the fig that are connected to a specific img id"

I am working with php / mysqli

Answer

Assign to yourID the value you nedd eg: 33

 select fig.* 
 from fig
 inner join link  on link.figid = fid.id
 inner join img on link.imgid = yourID 

in your case

 select fig.* 
 from fig
 inner join link  on link.figid = fid.id
 inner join img on link.imgid = 33
Comments