Santana Santana - 1 year ago 57
MySQL Question

Mysql query: JOINS

I have the following tables:

Transfers Table:

ID | storagefrom | storageto
1 | 2 | 3

Storages Table:

ID | Name
2 | Kitchen
3 | Main

I want to get the following result:

Storage1 | Storage2
Kitchen | Main

This is my query:

SELECT as Storage1, as Storage2
FROM transfers
LEFT JOIN storages ON = transfers.storagefrom
LEFT JOIN storages ON = transfers.storageto

Any tips?

Answer Source


       S1.Name Storage1, Storage2 
FROM transfers T
LEFT JOIN storages S1 ON S1.ID = T.storagefrom
LEFT JOIN storages S2 ON S2.ID = T.storageto

Refer : SQL Fiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download