select data from two different tables in mysql

Discussion in 'PHP' started by aleale, Jul 14, 2012.

  1. #1
    I have 2 tables : post and images.

    the structure of 'post' is id, post_title, post_date and post_content and structure of images is id, path, p_id. In p_id i am storing data the value of id from table 'post' now i want that only the path related corresponding id from table 'images' and other information from table post.

    how can i perform the operation, kindly help me, i am stuck here to complete my project.

    Thanks in advance.
     
    aleale, Jul 14, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    SELECT `post`.`id`,
    `post`.`post_title`,
    `post`.`post_date`,
    `post`.`post_content`,
    `images`.`id`,
    `images`.`path`
    FROM `post`
    LEFT JOIN `images` ON `images`.`p_id` = `post`.`id`
    WHERE `post`.`id` = 'YOURID'

    Have fun
     
    EricBruggema, Jul 15, 2012 IP