how to get rows??

Discussion in 'MySQL' started by php_techy, Jun 12, 2010.

  1. #1
    HI,
    In mysql, I have 2 tables friends, my_page.

    friends
    --------
    id int(11)
    username char(40)
    person char(40)
    type enum('Friend','Blocked')

    id username person type
    ------------------------------------------------------
    13 king_nothing Musechild Friend
    587 MrRogue ammo Friend
    17 Honey MrRogue Friend


    my_page
    --------
    id int(11)
    username varchar(30)
    page_owner varchar(30)
    date_posted datetime
    text text

    id username page_owner text date
    ------------------------------------------------------------
    4 Honey MrRogue PHP 2010-06-11 12:30:18
    5 ammo MrRogue java 2010-06-08 10:54:52
    6 mobster ammo both 2010-06-12 21:20:14
    7 ammo Wizkid wrong 2010-06-12 21:39:29
    8 Honey ammo show 2010-06-12 22:28:52

    friends table tells freinds of each member,
    say MrRogue is friend of ammo, Honey.Note that MrRogue can come in either username/person field, not necessarily to be in username field.

    Now I want rows from my_page where my_page.username, my_page.page_owner both are friends of MrRogue, like

    8 Honey ammo show 2010-06-12 22:28:52

    Thanks in advance!!!!
    Regards
     
    php_techy, Jun 12, 2010 IP
  2. NemoPlus

    NemoPlus Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like this?

    SELECT *
    FROM my_page
    WHERE username IN ( SUBQUERY1 )
    AND page_owner IN ( SUBQUERY1 )
    Code (markup):
    where SUBQUERY1 is
    SELECT username 
    FROM friends
    WHERE person = "MrRogue"
    UNION
    SELECT person
    FROM friends
    WHERE username = "MrRogue"
    Code (markup):
     
    NemoPlus, Jun 13, 2010 IP
  3. php_techy

    php_techy Active Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    Thanks for your help!!!!!!!
     
    php_techy, Jun 13, 2010 IP