Need help with a SQL Query

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2010-04-19T11:39:50Z Indexed on 2010/04/19 11:43 UTC
Read the original article Hit count: 114

Filed under:

I have created a table with the following structure-

$sql = "CREATE TABLE followers
    (
     uid int UNSIGNED NOT NULL UNIQUE,
     PRIMARY KEY(uid),
     follower_count int UNSIGNED ,
     is_my_friend bool,
     status_count int UNSIGNED,
     location varchar(50)
    )";

I need to find the uid of the person with max(status_count+follower_count) and whose is_my_friend = 1

I wrote the following query but I ain't getting the correct uid.

SELECT p.uid FROM (select uid,is_my_friend,max(follower_count+status_count) from followers) p WHERE p.is_my_friend = 1;

© Stack Overflow or respective owner

Related posts about sql