-1

这是我当前的查询:

SELECT DISTINCT t.* FROM filter AS f
INNER JOIN filter_thread AS ft 
ON ft.filter_id = f.filter_id
INNER JOIN thread AS t 
ON ft.thread_id = t.thread_id
WHERE f.tag LIKE '%test%'
ORDER BY t.replystamp DESC

它返回一堆数据,包括“owner_id”列。

'user_table' 包含一个匹配的 id,标记为 'id'

我以前使用此查询来获取数据:

SELECT username FROM users WHERE id='$user_id'"

我需要这些出现在同一个查询中!但是添加一个额外的 INNER JOIN 是行不通的。

4

2 回答 2

2

也许是这样:

SELECT DISTINCT t.*,u.username
FROM filter AS f
INNER JOIN filter_thread AS ft 
ON ft.filter_id = f.filter_id
INNER JOIN thread AS t 
ON ft.thread_id = t.thread_id
INNER JOIN users AS u
ON u.id = t.owner_id
WHERE f.tag LIKE '%test%'
ORDER BY t.replystamp DESC

只是一个猜测。

于 2012-05-08T18:17:07.843 回答
1

尝试以下操作:

SELECT DISTINCT t.*, u.username FROM filter AS f
   INNER JOIN filter_thread AS ft 
      ON ft.filter_id = f.filter_id
   INNER JOIN thread AS t 
      ON ft.thread_id = t.thread_id
   INNER JOIN users AS u 
      ON ft.owner_id = u.id
   WHERE f.tag LIKE '%test%'
   ORDER BY t.replystamp DESC
于 2012-05-08T18:17:07.313 回答