php - Mysql Join without duplicates(theory)? -
okay, before start it's mention have read (and tryed) countless topics here on stackoverflow , on internet, there seems no straight foward answer simple question.
so here goes situation:
table1 (id, name)
1,name1
2,name2
3,name3
table2 (id, id_table1, field_name)
1,1,field1
2,1,field2
what want display first table id , it's field "name" when there's record matches id_table1 in second table. tryed join, group, inner join, left join, nothing seems solve problem....
expected output:
id: 1 - name: name1
last code tryed:
select * table1 left join table2 on table1.id = table2.id_table1 group table1.id
this should away problem.
select table1.id, table1.name table1 inner join table2 on table1.id = table2.id_table1 group table1.id
Comments
Post a Comment