php - Join two tables with one table has multiple rows matching -


trying figure out if possible create query join tables, table 1 smaller table two, table 2 has multiple references matching table 1 entries, query output joining table 1 length preserved add more columns. not sure if makes sense here example of after

table 1                                  table 2 +-----------------------------+           +-----------------------------+ | id | english  |  definition |           | id | word_id  |  sentence   | +-----------------------------+           +-----------------------------+ |1   |    a1    |    blah     |           |1   |    1    |   blahblah1  | |2   |    b4    |    blah2    |           |2   |    1    |   blahblah2  | +-----------------------------+           |3   |    1    |   blahblah3  |                                           |4   |    2    |   blahblah4  |                                           |5   |    2    |   blahblah5  |                                           +-----------------------------+  ********* query should return ***************** +----------------------------------------------------------------+ | id | english  |  definition | sentence | sentence2 | sentence3 |  +----------------------------------------------------------------+ |1   |    a1    |    blah     | blahblah1|  blahblah2| blahblah3 | |2   |    b4    |    blah2    | blahblah4|  blahblah5|           | +----------------------------------------------------------------+   current query looks , results in $query = "select * t1 inner join t2 on t1.id = t2.word_id";  resulting in +----------------------------------------+ | id | english  |  definition | sentence | +----------------------------------------+ |1   |    a1    |    blah     | blahblah1| |1   |    a1    |    blah     | blahblah2| |1   |    a1    |    blah     | blahblah3|  |2   |    b4    |    blah2    | blahblah4| |2   |    b4    |    blah2    | blahblah5| +----------------------------------------+ 

i working php , mysql.

update!!

staying original query , manipulating results php getting performance too. let me know if need me post code.

you might looking group_concat()

select t1.id, t1.english,t1.definition, group_concat(t2.sentence order t2.id separator '|')  table1 t1 inner join table2 t2 on t1.id = t2.word_id group word_id 

sample fiddle


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -