mysql - Trouble with a simple inner join for multiple tables -


edit: made little change. added table db_supplier (supplier_id, supply_speed_id) , changed lookup_supply_speed (supplier_id, supplier_speed) lookup_supply_speed (supplier_speed_id, supplier_speed)

my tables:

db_supply  ----------------------------------------------- | supplier_id | supply_type_id | itm_id | stock | |-----------------------------------------------| | 1           | 1              | 33     | 3     | |-----------------------------------------------| | 2           | 2              | 28     | 1     |  -----------------------------------------------  db_supplier  ---------------------------------------- | supplier_id | supply_speed_id | etc... | |----------------------------------------| | 1           | 1               |        | |----------------------------------------| | 2           | 2               |        |  ----------------------------------------  lookup_supplier_name  ----------------------------- | supplier_id | supplier_name | |-----------------------------| | 1           | walter        | |-----------------------------| | 2           | jesse         |  -----------------------------  lookup_supply_type  ----------------------------------- | supply_type_id | supply_type_name | |-----------------------------------| | 1              | import           | |-----------------------------------| | 2              | delivery         |  -----------------------------------  lookup_itm  ------------------------ | itm_id | itm_name      | |------------------------| | 33     | pickles       | |------------------------| | 28     | burger        |  ------------------------  lookup_supply_speed  ------------------------------------ | supplier_speed_id | supplier_speed | |------------------------------------| | 1                 | fast           | |------------------------------------| | 2                 | slow           |  ------------------------------------  query 'burger' output table:  ---------------------------------------------------------------------- | supplier_name | supply_type_name | itm_name | stock | supplier_speed | |----------------------------------------------------------------------| | jesse         | delivery         | burger   | 1     | slow           |  ---------------------------------------------------------------------- 

problem: can't produce sql statement me supplier_speed column since lookup_supply_speed not have fk association db_supply (all other tables do).

sql below give me this: (we query itm_name e.g. burger)

 ----------------------------------------------------- | supplier_name | supply_type_name | itm_name | stock | |-----------------------------------------------------| | jesse         | delivery         | burger   | 1     |  ----------------------------------------------------- select  b.supplier_name,         c.supply_type_name,         d.itm_name,         a.stock    db_supply         inner join lookup_supplier_name b             on a.supplier_id = b.supplier_id         inner join lookup_supply_type c             on a.supply_type_id = c.supply_type_id         inner join lookup_itm d             on a.itm_id = d.itm_id   d.itm_name = 'burger' 

how can modify can join lookup_supplier lookup_supply_speed via db_supplier , join rest?

sqlfiddle: http://www.sqlfiddle.com/#!2/9635d/3

how this?

select  f.supplier_name,         b.supplier_id,         c.supply_type_name,         d.itm_name,         a.stock,         e.supplier_speed    db_supply         inner join db_supplier b             on a.supplier_id = b.supplier_id         inner join lookup_supplier_name f             on f.supplier_id = b.supplier_id         inner join lookup_supply_type c             on a.supply_type_id = c.supply_type_id         inner join lookup_itm d             on a.itm_id = d.itm_id         inner join lookup_supply_speed e             on e.supplier_speed_id = b.supply_speed_id   d.itm_name = 'burger' 

http://www.sqlfiddle.com/#!2/be1a2/3


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -