0

So my scenario is, in a single query I have to select data from 4 tables. There is one to many relationships between booking and booking details and each booking detail has one test associated to it.

Query I wrote:

  $fetch_test = "SELECT br.id, b.bookingno, p.firstname, p.lastname, t.title
  from booking_rider br, bookings b, patients p, booking_details d, tests t 
  where br.bid = b.id and d.bid = b.id and t.id = d.tid and b.uid = p.id  and br.rid = 0 group by d.bid  " ;

Basically in one booking there are many tests.. This query is returning me just one test title.

I want it a json object of all test titles inside the result. How to achieve it?

Maha Waqar
  • 585
  • 1
  • 10
  • 24
  • There are 5 tables in the query. BTW, queries are more understandable if you use ANSI JOIN syntax. – Barmar Jun 30 '21 at 15:20
  • `GROUP BY d.bid` means you'll just get one row for each booking. Get rid of that if you want all the booking details. – Barmar Jun 30 '21 at 15:23
  • @Barmar if I remove group by -> it gives me multiple results with each test title. I want single result with group of tests under it – Maha Waqar Jun 30 '21 at 16:06
  • That's a presentation issue, not done in the query. – Barmar Jun 30 '21 at 16:15

0 Answers0