我有四張表commenttable,posttable,usertable和notifications表。我想建立一個通知系統。該通知表具有以下MYSQL JOIN查詢通知
column id,
notifier,
notifying,
date,
type,
typeid
類型可以是1或2。如果是1,這是一個註釋,如果是2,這是一個職位。
我想建立一個MySQL查詢,獲取用戶的所有通知,並根據類型將它們與註釋表,表格連接在一起。例如,如果type是1並且type id是300,那麼它將從可調整內容中提取評論列,如果它的值爲2,那麼它將從帖子表中提取帖子列。是
在後列如下:
postid, post and commenttable commenter, comment, commentid
我已經建立了一個查詢,如下所示,但它不喜歡工作,我希望它
SELECT
notificationstable.who,
notificationstable.type,
notificationstable.timestamp,
notificationstable.date,
commenttable.comment,
commenttable.commentid,
usertable.username,
usertable.avatar,
usertable.userid,
usertable.verified,
posttable.photo,
posttable.title,
posttable.postid
from
notificationstable
inner join
usertable
inner join
posttable
inner join
commenttable ON notificationstable.who = usertable.userid
and posttable.postid = notificationstable.type
and commenttable.commentid = notificationstable.type
where
notificationstable.whom = '$userid'
order by notificationstable.date desc
$userid
是PHP變量
「這是行不通的像我希望它」是一個非常糟糕的問題說明,如果你想人來幫助你。 – PeeHaa
它在做什麼不是你所期望的?你在期待什麼? – crush
它給你什麼結果?你期望什麼結果。如果您要將表和一些數據放入SQL小提琴中供我們使用,那將會很有幫助。 –