1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Equivalent to subquery query? By using JOIN.

Discussion in 'MySQL' started by Om ji Kesharwani, Dec 30, 2010.

  1. #1
    $result=mysql_query("select * from signup_form where id IN(select friend_id from user_relationships where user_id=1)");
    while($row=mysql_fetch_array($result))
    {
    echo $row['username']."<br/>";
    }


    Above is the example of subquery. Please change it by using JOIN because subquery is taking more time.
     
    Om ji Kesharwani, Dec 30, 2010 IP
  2. jkl6

    jkl6 Peon

    Messages:
    70
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    SELECT * FROM signup_form A, user_relationships B
    WHERE A.id=B.friend_id AND B.user_id=1
     
    jkl6, Dec 30, 2010 IP
  3. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #3
    
    SELECT * FROM signup_form S
    [INDENT]INNER JOIN user_relationships R[/INDENT]
    [INDENT]ON S.ID = R.ID[/INDENT]
    [INDENT][INDENT]WHERE S.ID = 1[/INDENT][/INDENT]
    
    Code (markup):
     
    vic_msn, Jan 2, 2011 IP