-2

I have table :

===================
|id| word | source|
===================
| 1| I    |   S1  |
| 2| me   |   S1  |
| 3| you  |   S1  |
| 4| me   |   S2  |
===================

If the are same datas in word that have different source, I just wanna take data word from source = S1

How to get them? I tried using below code, but still wrong :

$query = mysql_query(" SELECT word from tb where source ='S1' group by word1 ");
4

2 回答 2

1

Your group by column name is incorrect.

It should be word instead of word1.

Like so:

$query = mysql_query("SELECT word FROM tb WHERE source ='S1' GROUP BY word");
于 2012-10-21T11:19:58.350 回答
1

Then, I think, you need to get the minimum source using MIN().

SELECT WORD, MIN(source)
FROM tableName
GROUP BY word

SQL Fiddle demo

于 2012-10-21T11:20:22.123 回答