SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question how do i solve this query

    Hello friends,


    Table: activities
    Code:
        id     uid   bid  
    ------  ------  ------
         1       2       0
         2       4       0
         3       3       2
         4       2       5
         5       6       0
         6       7       0
    In the above table, uid is user id and bid is buddy id. with this information I want a result result below
    Code:
        id     uid   bid     newfield
    ------  ------  ------  ---------
         1       2       0       2
         2       4       0       4
         3       3       2       2
         4       2       5       2
    All i need is how am I related to the records in the activity table. For instance user id 1 has 2 friends (2,4) which friend of mine is related to the record (newfield column in the above resultset)


    all i can think is only this, so i'm seeking your help

    SELECT id,uid, bid FROM activities WHERE uid IN (2,4) OR bid IN (2,4)

    Code:
        id     uid   bid  
    ------  ------  ------
         1       2       0
         2       4       0
         3       3       2
         4       2       5

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    why do some users have buddy 0? what does that mean?

    and when you say "I want a result result below" could you please describe in words what you're trying to do?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •