这对我来说很难。我有一个包含用户通知的表。有一列“VIEWED”,其中0表示尚未查看,1表示已查看。
我想生成我的通知列表,SELECT *是未查看的(0),但是如果我没有未查看的通知,我不想只显示“没有通知”我想显示一个几个旧的。
我已经开始展示我最近的未见过的了。有没有办法做一些显示所有未查看的内容,但只有少数人看过?如下所示?
$QUERY= "SELECT * FROM point_member_notifications WHERE account_id='$accountid' ORDER BY viewed ASC, created_date DESC (LIMIT 10 WHERE VIEWED='1') "
答案 0 :(得分:0)
也许您希望UNION ALL
限制&{39;} VIEWED'
旧的,只需将limit
子句放在括号SELECT
(SELECT * FROM point_member_notifications WHERE account_id='$accountid' ORDER BY viewed ASC)
UNION ALL
(SELECT * FROM point_member_notifications WHERE account_id='$accountid' WHERE VIEWED='1' created_date DESC LIMIT 10);