我正在编写一个查询以获取mysql中的好友列表。查询正确获取结果。
这是我正在使用的查询:
SELECT (
SELECT COUNT( * )
FROM
cpo_conversation_reply
WHERE
user_id_fk = u.id
AND user_id_rec = $user_id
AND read_unread_status =0
AND c.property_id = p_id
) AS unread_msg,
u.id AS user_id, c.c_id, u.first_name, u.last_name, u.user_name,
u.online_status AS loginstatus, c.user_one, c.user_two, u.user_img,
c.property_id, p.locality, p.city, c.online_status
FROM
cpo_conversation c,
property_register u,
property_for_sale p
WHERE
CASE
WHEN c.user_one = '$user_id' THEN c.user_two = u.id
WHEN c.user_two = '$user_id' THEN c.user_one = u.id
END
AND (
c.user_one = '$user_id'
OR c.user_two = '$user_id'
)
AND p.id = c.property_id
ORDER BY
c.c_id DESC
现在我想要隐藏已删除的聊天的朋友..
为此我在条件中添加以下条件:
c.hide_chat_1 != '1' OR c.hide_chat_2 != '1'
之后,这个查询是这样的:
SELECT (
SELECT COUNT( * )
FROM
cpo_conversation_reply
WHERE
user_id_fk = u.id
AND user_id_rec = $user_id
AND read_unread_status =0
AND c.property_id = p_id
) AS unread_msg,
u.id AS user_id, c.c_id, u.first_name, u.last_name, u.user_name,
u.online_status AS loginstatus, c.user_one, c.user_two, u.user_img,
c.property_id, p.locality, p.city, c.online_status
FROM
cpo_conversation c,
property_register u,
property_for_sale p
WHERE
CASE
WHEN c.user_one = '$user_id' THEN c.user_two = u.id
WHEN c.user_two = '$user_id' THEN c.user_one = u.id
END
AND (
c.user_one = '$user_id'
OR c.user_two = '$user_id'
)
AND (
c.hide_chat_1 != '1'
OR c.hide_chat_2 != '1'
)
AND p.id = c.property_id
ORDER BY
c.c_id DESC
但隐藏聊天状态的朋友不是隐藏1
。
有人可以帮我这个吗?
答案 0 :(得分:0)
请改用:
c.hide_chat_1 <> '1'
OR c.hide_chat_2 <> '1'