0

当我尝试运行此查询时:

 select * FROM `activity` 
 WHERE user_id = 1
 AND activity_id NOT LIKE (select activity_id from activity where user_id = 1 ORDER BY activity_id DESC LIMIT 8)

我收到以下错误:

 Subquery returns more than 1 row

我怎么解决这个问题?我想从表中选择活动 ID,不包括某个用户的最新 8 个活动 ID。

4

2 回答 2

3

NOT LIKE 期望一个表达式或一个值来比较,而不是一个结果集。将 NOT LIKE 更改为 NOT IN

试试这个:

    SELECT * FROM `activity` 
             WHERE user_id = 1 AND activity_id NOT IN (
                     SELECT activity_id FROM activity WHERE user_id = 1 
                                        ORDER BY activity_id DESC LIMIT 8)
于 2012-10-31T22:42:17.290 回答
0

通过这样做解决了它:

                $sql2 = "DELETE t1.*
                        FROM activity t1
                        left join (select activity_id from activity where user_id = '".$row['user_id']."' ORDER BY activity_id DESC LIMIT 8) t2
                        on (t1.activity_id = t2.activity_id)
                        where t2.activity_id is null
                        and t1.user_id = '".$row['user_id']."'";
于 2012-11-02T14:05:02.400 回答