I don't know whether it is possible in MySQL or not. If someone has tried it, will reduce my time and number of lines in the code.
I have rating table, which has the following field
I have reason table, which has the following fields,
Also i have mapping table called rating_reason_mapping for mapping rating table and reason table
And i have the below query to fetch the details of these tables
SELECT ratings.id AS rating_id, ratings.user_id, ratings.mdn, ratings.rating_value, ratings.rated_time, ratings.comment, reasons.reason
FROM ratings, reasons
JOIN rating_reason_mapping
WHERE rating_reason_mapping.rating_id = ratings.id
AND reasons.id = rating_reason_mapping.reason_id
Of course it will display the result like below,
But this is not the result i am expecting one , i don't want the repetation of all the rows instead i need the reasons in an array.For example you can see that rating_id
59
has repeated three times. All the values except the reasons are same for these three. I don't need this to be repeat in three times. I just need this in one time only. But i need all the reasons of the three rows. The reasons should be in an array.Like below
Of course the rating id 71,46,47 and 20 will have values in the above result
Is this possible in MySQL ???