Need Help! Retrieve data from two tables

Discussion in 'Databases' started by AarAwan, Aug 20, 2013.

  1. #1
    Hello guys,
    I am stuck in problem. I want to retrieve data from two table in SQL.
    Here is Sample

    Table 1= categories
    category_id, category_name
    1, Graphic Design
    2, Web Design
    3, Freebie

    Table 2= stories
    story_id, story_category, story_title
    1, 1, Title_one
    2, 3, Title_two
    3, 2, Title_three

    I want the new table in this form

    Story_id, category_name, story_title
    1 Graphic Design Title_One
    2 Freebie Title_two
    3 Web Design Title Three

    Any help would be Highly appreciated.
    Thanks in Advanced
     
    AarAwan, Aug 20, 2013 IP
  2. marht

    marht Active Member

    Messages:
    142
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    58
    #2
    Hi AarAwan,
    Try using the following query:

    SELECT s.story_id, c.category_name, s.story_title FROM categories as c
    INNER JOIN stories as s
    ON c.category_id = s.story_category
    Code (markup):
    Assuming your story_category = INT

    Hope this helps you out,

    Kind regards,

    Maarten
     
    marht, Aug 21, 2013 IP