I am working on a query which contains multiple rows per a particular id and im looking to display them all on one line.
The query I currently have is :
SELECT
person_id,
car_name,
car_year,
car_value,
car_mileage
FROM tbl_motor_vehicles
This returns the below:
person_id car_name car_year car_value car_mileage
---------------------------------------------------------------------
1 TOYOTA YARIS 2017 5000 10000
1 Nissan Micra 2001 1000 15000
2 Golf 15000 700000
2 Fiat Punto 2002 2500 60000
I need this to display on one line per id with each car getting its own column like below :
Person ID Car_1_NAME Car_1_year car1_value car1_mileage Car_2_NAME Car_2_year car2_value car2_mileage
--------------------------------------------------------------------------------------------------------------------------------------
1 TOYOTA YARIS 2017 5000 10000 Nissan Micra 2001 1000 15000
2 Golf 2007 15000 700000 Fiat Punto 2002 2500 60000
Can anyone advise me how to go about this ?