locked
How to Fetch Data From 3 Tables WITH Their Internal Relations RRS feed

  • Question

  • hi 

    I Have 3 Tables:

    User_Table:                                  Friend_Table:                Post_Table:

    RankId   Name   ImagePath           Id     FriendId   MyId       Id   PostId   RankId  PostMessage

    We Have Only One ParaMeter SessionId(RankId)   Which Is in  Post_Table And UserTable Named As RankId

    In Friend Table I Have Stored FriendId On Postion FriendId Or MyId Depends On Sending And Recieving Requests

    now the qusetion is this:i want to show Name,ImagePath FROM UserTable And PostMessage FROM Post_Table 

    ByChecking Either He/she is added with me in Friend_Table .

    Give Me Any Other Ideas If U Have.

    Please Help me 

    thanks in advance

    Saturday, July 20, 2013 10:07 AM

All replies

  • QUERY:

    SELECT

              UT.Name, UT.ImagePath ,PT.PostMessage

    FROM USER_TABLE UT

    INNER JOIN FRIEND_TABLE FT ON FT.MYID = UT.RANKID 

    INNER JOIN POST_MESSAGE PT ON UT.RANKID = PT.RANKID

    WHERE PT.RANKID = SessionId(RankId)

    -- FIRST JOIN STATEMENT JOINS USERS & FRIENDS ELIMINATES NON-FRIENDS

    -- SECOND JOIN ELIMINATES THE USERS WITHOUT MESSAGES

    -- WHERE CONDITION FILTERS THE RECORDS FOR A PARTICULAR USER.

     SessionId(RankId) passed as a parameter to a query or sp.
    Saturday, July 20, 2013 10:27 AM
  • Its Give me Only My Messages 

    IF My Friend Also PostMessage It should also display

    • Marked as answer by k k k Saturday, July 20, 2013 10:47 AM
    • Unmarked as answer by k k k Saturday, July 20, 2013 10:47 AM
    • Marked as answer by k k k Saturday, July 20, 2013 11:30 AM
    • Unmarked as answer by k k k Saturday, July 20, 2013 11:30 AM
    • Marked as answer by k k k Saturday, July 20, 2013 11:30 AM
    • Unmarked as answer by k k k Saturday, July 20, 2013 11:30 AM
    Saturday, July 20, 2013 10:35 AM