php - MySQL query select from multiple tables, display all from table1 + some data from table2 -
i have 2 tables. want print out all access-lists table1, plus interface table2. access-lists don't have associated interface access-list (but still want print these access-lists). how do this? (i can't desired result result ._.)
table1
| id | access-list | ... +----+--------------+ | 0 | list_1 | ... | 1 | list_2 | ... | 2 | list_3 | ... | 3 | list_4 | ...
table2
| id | access-list | interface | +----+--------------+-----------+ | 0 | list_1 | iface0 | | 1 | list_4 | iface1 |
the expected result:
0 list_1 iface0 bla bla bla 1 list_2 bla bla bla 2 list_3 bla bla bla 3 list_4 iface1 bla bla bla
select * table1 t1 left join table2 t2 on t1.access_list = t2.access_list
when need data 1 table, , data matches table, outer join
way go. left join
short left outer join
, , specifies table (the 1 on left of join
statement) have data returned. can use right join
, name tables other way round (i.e. table1 left join table2
equivalent table2 right join table1
), left join
syntax more common.
a join returns matching data both tables known inner join
, abbreviated join
.
Comments
Post a Comment