I am having following query to fetch message and images from two different table.
Here One message can have multiple images
for that i have written following query which is working properly and showing following result
select msg.messageid, msg.message, msg.sentby, msg.adddate,
p_i.image_id ,p_i.small_pic_path
from user_messages as msg
LEFT JOIN post_images as p_i
on msg.messageid=p_i.messageid
where msg.messageid='zpx1btrpvpa1360154523078'
order by msg.adddate desc
Output is
messageid message sentby adddate image_id small_pic_path
1 abc aa 12/2/12 6 /sdf/sdf
1 abc aa 12/2/12 7 /asdf/df
1 abc aa 12/2/12 8 /cxd/sxc
1 abc aa 12/2/12 9 /zz/szz
Here messageid message sentby adddate is repeating and while displaying in jsp page
showing total 4 different message.
But I want to show 4 imageid and small_pic_path(based on message id) with a relevent message detail
I want to display as
1) Message
sentBy
all small_pic_path of messag id of this message
1) Message
sentBy
all small_pic_path of messag id of this message
2) Message
sentBy
all small_pic_path of messag id of this message
3) Message
sentBy
all small_pic_path of messag id of this message
Without really understanding your requirements, you write:
How do you want to show those records?
Assuming you mean on the same line, then look into using
GROUP_CONCAT:Here’s a SQL Fiddle to demonstrate the results.
If you are wanting to show the results differently, chances are you should handle that via the UI.
Best of luck.