MYSQL query problem.

Discussion in 'MySQL' started by Force, Oct 23, 2008.

  1. #1
    Ok heres the deal.

    I have two tables

    TableK -
    user
    user2

    TableU
    user
    username

    current Query

    
    SELECT k.user, p.username, k.user1, count(k.user1)
    FROM TableU AS P, TableK as K
    WHERE k.user = p.user
    GROUP BY k.user, p.username, k.user1
    ORDER BY count(k.user1)
    
    Code (markup):
    i want to also be able to see user1's username.

    i just cant seem to figure it out. Any help would be appreciated

    ~thanks
     
    Force, Oct 23, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    I would format this query like this:

    
    SELECT k.user, k.user1, count(k.user1) AS count, p.username  
    FROM TableU AS p LEFT JOIN TableK as k
    ON p.user = k.user
    GROUP BY k.user, p.username, k.user1
    ORDER BY count(k.user1)
    
    Code (markup):
    I'm not sure about your GROUP BY clause. You may need to mess with it to get this to work properly.
     
    jestep, Oct 23, 2008 IP
  3. Force

    Force Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Note taken,

    im willing to try anything The things i need to be displayed are

    User1's username
    User2's username
    the count of User2
     
    Force, Oct 23, 2008 IP