我一直在試圖整天理清MySQL查詢:(任何幫助將是巨大的。與表Mysql數據庫幫助
我想涉及三件事情。菜單項,菜單項組和。特權級別
所以,我有五個表:
一個的菜單項表 ID(唯一的)
我有一組表 組ID(唯一的)
和menuIdGroupId表 的groupId 菜單ID
我有一個特權表 privilegeid(唯一的)
和groupsPrivlstable idGroups idPrivilege
特權表和組表是真的只有列表組和特權。特權組表和groupMenu表都是要連接表來關聯所有內容。
我已經嘗試了很多組合的查詢,並沒有工作:
SELECT *
FROM `menuIdGroupId`
JOIN `menuItems` ON menuItems.id = menuIdGroupId.menuId
JOIN `groupsPrivls` ON groupsPrivls.idGroups = menuIdGroupId.groupId
WHERE groupsPrivls.idPrivilege = '1'
LIMIT 0 , 30
如果groupsPrivls是
idGroups idPrivilege
7 0
7 1
1 1
1 2
1 4
13 5
9 2
12 1
1 5
1 6
7 2
7 4
7 5
7 6
和menuIDGroupId
groupId menuId
1 30
7 29
1 31
1 29
1 33
7 33
4 33
1 32
7 30
7 31
id text
33 button 3
32 button 2
31 button 1
30 Church
29 About
結果是
groupId menuId id text idGroups idPrivilege
7 29 29 About Us 7 1
7 33 33 button 3 7 1
7 30 30 New to Church 7 1
7 31 31 button 1 7 1
1 30 30 New to Church 1 1
1 31 31 button 1 1 1
1 29 29 About Us 1 1
1 33 33 button 3 1 1
1 32 32 button 2 1 1
正如你可以看到我得到重複的條目,我不明白爲什麼。我猜我沒有設置八個。任何幫助都會很棒。
感謝
艾倫
PS對不起格式是如此凌亂!
你想要的輸出是什麼? – 2011-06-14 16:51:00