开发者

joining four tables

I have three tables that I'm wondering If I should join, the tables are structured as follows:

members                                                          

member_id    login    


permissions

K_id    member_id   date


kcontent

K_id    id    content  


ktitle

K_id          title

What I'm trying to do is, that for a specific member (member_id)....get each K_id that each member is linked to, order them by date DESC, and then get开发者_运维百科 the content from kcontent ordered by id and title from ktitle


Yes, you should.

Try something along these lines:

SELECT a.member_id, b.date, d.title, c.content
FROM members as a
JOIN permissions as b
ON b.member_id = a.member_id
JOIN kcontent as c
ON c.k_id = b.k_id
JOIN ktitle as d
ON d.k_id = b.k_id
WHERE a.member_id = {inputMemberId}
ORDER BY b.date, d.k_id, d.title


SELECT *
FROM 
PERMISSIONS INNER JOIN KCONTENT
ON PERMISSIONS.K_ID = KCONTENT.K_ID
INNER JOIN KTITLE
ON KCONTENT.K_ID = KTITLE.K_ID
INNER JOIN MEMEBRS
ON MEMBERS.MEMBER_ID = PERMISSIONS.MEMBER_ID
WHERE MEMBERS.MEMBER_ID = ###
ORDER BY PERMISSIONS.DATE, MEMBERS.MEMBER_ID
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜