0

Here I have 2 tables

  • trips : trip_id, customer_id, trip_status
  • customers : customer_id, customer_name, customer_phone

Every trip has one customer and i joined the both table using inner join

I tried this way

SELECT * from trips JOIN customers ON trips.customer_id = customers.customer_id limit 1

This gives me a single row with both table data

i need something like

{
  "trip_id": "12",
  "trip_status": "CLOSED",
  "customer": {
    "customer_name": "A",
    "customer_phone": "0123335566",
    "customer_id": "1"
  }
}

I need the customer table inside another object.

Thanks in advance

  • Adaptation example [db<>fiddle](https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=9adb8f8750e8ab1736fba13ec5de2d97) of duplicate for use-case – Will B. May 25 '22 at 04:54

0 Answers0