Help Required for joining 2 Tables in MySQL

Discussion in 'MySQL' started by Sudhir36, Sep 24, 2013.

  1. Sudhir36

    Sudhir36 New Member

    Joined:
    Sep 24, 2013
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.badricreatives.in
    Hello Friends,

    I need help in Joining 2 Tables.

    1st table with Created community details

    SQL>> SELECT * FROM comm;

    Cid cname userid
    1 xxx 311
    2 yyy 311
    3 zzz 311
    4 xyy 64
    5 zzy 64
    6 xxz 64


    2nd table with Joined community details

    SQL>> SELECT * FROM joincomm;

    id cid userid
    1 xyy 311
    2 zzy 311
    3 xxz 311

    Now i want both i joined and created records

    Example

    cname userid

    xxx 311
    yyy 311
    zzz 311
    xyy 311
    zzy 311
    xxz 311

    Can u please help me out to solve this query
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,341
    Likes Received:
    379
    Trophy Points:
    83
    Do you want to be creating table or want to display content by joining tables?
     
  3. Sudhir36

    Sudhir36 New Member

    Joined:
    Sep 24, 2013
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.badricreatives.in
    Want to Display Content by Joining tables
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,341
    Likes Received:
    379
    Trophy Points:
    83
    Code:
    Select * from comm as c INNER JOIN joincomm as jc ON (c.userid = jc.userid)
     
  5. Sudhir36

    Sudhir36 New Member

    Joined:
    Sep 24, 2013
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.badricreatives.in

    Hello Shabbir,

    Thanks for the reply but its unfortunate, It Doesn't Satisfy my condition.....

    Here is the Requirement,

    My UserId = 311

    I created 3 communities like ( CommunityID = 111,112,113)

    I Joined 3 Communities Which were created by Others like (Community ID = 222,223,224 Note: let us think these 3 communities were created by user 312)

    Now i result must be Showing all 6 communities (111,112,113,222,223,224)

    This is The Requirement...
    Can u please help me out to solve this issue
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,341
    Likes Received:
    379
    Trophy Points:
    83
    The issue is not with the display of Data but then you are not storing the data correctly.
     
    Sudhir36 likes this.
  7. Sudhir36

    Sudhir36 New Member

    Joined:
    Sep 24, 2013
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.badricreatives.in
    Storing of Data every thing is fine Shabbir, as i cant share the Data here. I given a Sample example.

    Is it Possible to retrieve data in that way
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,341
    Likes Received:
    379
    Trophy Points:
    83
    If you have userid based on which the data is stored in both tables and joining them does not give the data then I am not sure.
     
    Sudhir36 likes this.
  9. Sudhir36

    Sudhir36 New Member

    Joined:
    Sep 24, 2013
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.badricreatives.in
    Ok Shabbir, Thanks allot for the Help
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,341
    Likes Received:
    379
    Trophy Points:
    83
    The pleasure is all mine.
     
    Sudhir36 likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice