I have two tables trips and users. Whenever an user posts a trip, it stores id of the user as foreign key. And while fetching, I am joining those two tables the following way.
Query:
SELECT title, starting_point, ending_point, distance, trips.created_on
FROM trips
JOIN users ON (users.id=trips.created_by);
Result:
{
"title": "lorem ipsum",
"starting_point": "Location A",
"ending_point": "Location B",
"distance": 20,
"created_on": "2020-07-27T18:15:00.000Z",
"author": "Test user"
},
Result needed.
{
"title": "lorem ipsum",
"starting_point": "Location A",
"ending_point": "Location B",
"distance": 20,
"created_on": "2020-07-27T18:15:00.000Z",
"author": {
"id":1
"name": "Test user",
"role": "admin"
}
},
In short, I want to join user table with trips table but I want to separate the content of user table in different alias in trip.