0

尝试选择所有列但避免超过 1 个相同的用户 ID。

$result = mysql_query("select *, DISTINCT userid from ringtones where deletedbyuser='0' and (lang='$lang' or lang='en') order by id desc limit 10");

请帮忙。

表结构:

id  int(10)
userid  int(10)
artist  varchar(100)
title   varchar(100)
lang    varchar(2)
public  int(1)
status  int(1)
deletedbyuser   int(1)
4

1 回答 1

3

你可以

select r.* from ringtones r 
    inner join (select MIN(id) as id, userid from ringtones 
                      where deletedbyuser='0' and (lang='$lang' or lang='en') 
                      group by userid) s
    on r.id = s.id
order by r.id desc
limit 10

如果有多个,这将选择添加的第一个。

于 2012-05-29T03:31:39.297 回答