php - MySQL join data from same table twice -


i have table info 3 rows: id,monter1,monter2. monter1 , monter2 id's table monterzy (id, name, surname) want join with. problem cant make proper query pick these values in php. have:

select i.id      , m.name      , m.surname    info   join monterzy m     on i.monter1 = m.id; 

i want expand monter2 , corresponding name , surname. have searched on google, there examples have no idea how it. thanks!

you need join same table twice different alias names

select info.id,         m1.name m1_name, m1.surname m1_surname,        m2.name m2_name, m2.surname m2_surname info  inner join monterzy m1 on info.monter1 = m1.id inner join monterzy m2 on info.monter2 = m2.id 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -