0

Hi Guys is there is direct way to format data within sql query to avoid loops. For example : Suppose there 2 tables as following tbl1(id,name,value) tbl2(id,tbl1_id,name) // tbl1_id is primary key of tbl1

Now tbl2 can have multiple records with same tbl1_id. Now how to get formatted data where I can get multiple records for tbl1 and then tbl2 array under id of tbl1 ?

Lk Thanvi
  • 87
  • 1
  • 9
  • What are your expected results? Perhaps you are looking to use `group_concat`? – sgeddes Aug 01 '16 at 18:21
  • You do a JOIN, of course. In order of tbl1_id. Then you need to extract those data. In what language did you try to do that? And where's your code? – LSerni Aug 01 '16 at 18:22
  • I guess this would be helpful ? http://stackoverflow.com/questions/383631/json-encode-mysql-results – Prashant Majhwar Aug 01 '16 at 18:24
  • Hi @sgeddes I was looking for json where from tbl1 lets say 3 records and under every record from tbl1 there will multiple records from tbl2 referencing tbl1. this is one to many ref for every record in tbl1 to tbl2 on tbl1_id column. – Lk Thanvi Aug 02 '16 at 09:35

0 Answers0