获取用户未加入的最近线程 [英] Get recent threads that the user did not join in to

查看:44
本文介绍了获取用户未加入的最近线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们试图简单地从相关用户尚未加入的表中列出最近的线程.

We're trying to simply list recent threads from a table that the user in question hasn't joined in to yet.

下面的代码不起作用(显示了用户已经加入的新线程线程),但显示了我们正在使用的表:

The code below does not work (shows both new threads and threads that the user already joined in to), but shows what tables we're using:

SELECT t.*, jt.*
FROM thread t 
INNER JOIN joined_threads jt ON jt.thread_id = t.unique_id
WHERE t.owner != '$user_id'
AND jt.saved_by != '$user_id' 
GROUP BY t.unique_id

使用过的表格:

THREAD:
unique_id
owner
title
content
date

JOINED_THREADS:
saved_by
thread_id

我想这对你们大多数人来说都很容易:)

I presume this is very easy for most of you :)

推荐答案

如果我了解您的需求

SELECT t.*, jt.*
FROM thread t 
LEFT JOIN joined_threads jt ON jt.thread_id = t.unique_id AND jt.saved_by = '$user_id' 
WHERE t.owner <> '$user_id' AND jt.thread_id is NULL
GROUP BY t.unique_id

(未测试).顺便说一句,你需要什么 jt.*,总是 NULL

(not tested). Btw what for do you need jt.*, would be always NULL

这篇关于获取用户未加入的最近线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆