2013-10-02 30 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)