2013-10-02 33 views
-2

两者合用列选择独特的元组我有一个表:基于MySQL的

|------------|---------------|----------------|---------------| 
| id  | social_media | post_userid | value  | 
|-------------------------------------------------------------| 
|  1  | facebook | 1000012  |  12  | 
|------------|---------------|----------------|---------------| 
|  2  | facebook | 1000012  |  14  | 
|-------------------------------------------------------------| 
|  3  | twitter | 10023  |  12  | 
|-------------------------------------------------------------| 
|  4  | facebook | 1000014  |  12  | 
|-------------------------------------------------------------| 
|  5  | google plus |  123  |  14  | 
|-------------------------------------------------------------| 

在表中我有2 facebook users having id 1000012 and 1000014 one twitter user having id 10023one googleplus user having id 123

所以social_mediapost_userid组合标识一个唯一的用户。

那么我怎样才能得到一个不同的用户基于social_mediapost_userid的组合?

+0

这是一个有趣的问题? SELECT DISTINCT social_media,post_userid FROM一个表; !?!?!?! – Strawberry

回答

1
SELECT DISTINCT social_media, post_userid FROM my_table 
-1

尝试

Select id ,social_media , post_userid , value 
From table t1 
Where id = (Select Max(id) from table t2 
       where t1.post_userid = t.post_userid)