2013-10-02 4 views
-2

J'ai une table:Sélection tuple unique basé sur deux colonnes combinées dans 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  | 
|-------------------------------------------------------------| 

Dans le tableau je 2 facebook users having id 1000012 and 1000014 one twitter user having id 10023 et one googleplus user having id 123.

Ainsi, les codes social_media et post_userid combinés identifient un utilisateur unique.

Alors, comment puis-je obtenir un utilisateur distinct basé sur une combinaison de social_media et post_userid?

+0

Est-ce une question piège? SELECT DISTINCT social_media, post_userID FROM une table; !?!?!?! – Strawberry

Répondre

1
SELECT DISTINCT social_media, post_userid FROM my_table 
-1

essayer

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) 
Questions connexes