0

i have a table one table message and other table is image . i want to fetch the data from image for the selected row from the message ( idea is that i want to display the images of sender that are stored in other table "IMAGE" and message are stored in other table "Message" Please help . this is not working

select  msg.Uid, msg.Fid, msg.Message, img.ImagePath, img.Uid 
FROM Message msg left OUTER JOIN Image img 
ON 
msg.Uid=img.Uid 
Kapil Dev
  • 11
  • 1
  • 8

1 Answers1

0

We would need to know more about the tables, but just by looking at the column names it seems you are using the wrong Uid's. If you have a one-to-many (since you are saying "images from sender") relation from Message to Image, and each table has their own Uid, then on the Image table you should have a foreign key pointing to the Uid from Message, and the query would look something like this:

SELECT  msg.Uid, msg.Fid, msg.Message, img.ImagePath, img.Uid 
FROM    Message msg 
        LEFT JOIN Image img ON msg.Uid = img.MessageUid
user1845791
  • 993
  • 2
  • 9
  • 17