1

Say I have a table with some columns as

-conversation_id,

-col2,

-user_id.

I want to grab all the rows corresponding to user_id. There could be, say, 20 rows returned for a particular, but there are only say 3 unique conversation_id values.

What is the fastest way to get these values, rather than going through each one and figuring out the unique ones?

I must say, I mean this in PHP!

Thankss!!

4

5 回答 5

0

你可以试试这个

select distinct conservation_id,user_id
from table 
group by user_id
于 2012-10-31T05:57:09.553 回答
0
$query = "SELECT DISTINCT conversation_id 
          FROM conversations 
          WHERE user_id='2'";
于 2012-10-31T05:53:46.120 回答
0
SELECT conversation_id, user_id
      FROM conversations
      GROUP BY user_id, conversation_id
于 2012-10-31T05:54:35.673 回答
0
SELECT DISTINCT conversation_id FROM conversations WHERE user_id = userID

使用zend函数从表中获取不同的记录?

于 2012-10-31T06:07:11.083 回答
0

DISTINCT 关键字用于从结果集中仅选择唯一项。

如果是zend,则为ex:

$db->select()->distinct('u.conversation_id')->from(array('u'=>'user'))->where('u.user_id = ?',$user_id);

于 2012-10-31T06:23:17.940 回答