如果表中的 userItems 没有与 moduleItems 连接的记录为空,如何获取?
SELECT `users`.*, `useritems`.*, `moduleitems`.*, `modulesubitems`.* FROM `users`
LEFT JOIN `useritems` ON useritems.f_user_id = users.user_id
LEFT JOIN `moduleitems` ON moduleitems.moduleItem_id = useritems.f_moduleItem_id
LEFT JOIN `modulesubitems` ON modulesubitems.modulesubitem_id = useritems.userItem_value
编辑:我的数据库结构
CREATE TABLE IF NOT EXISTS `moduleitems` (
`moduleItem_id` int(11) NOT NULL AUTO_INCREMENT,
`f_module_id` int(11) NOT NULL,
PRIMARY KEY (`moduleItem_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=63 ;
CREATE TABLE IF NOT EXISTS `modules` (
`module_id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`module_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS `modulesubitems` (
`moduleSubitem_id` int(11) NOT NULL AUTO_INCREMENT,
`f_moduleItem_id` int(11) NOT NULL,
PRIMARY KEY (`moduleSubitem_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ;
CREATE TABLE IF NOT EXISTS `useritems` (
`f_user_id` int(11) NOT NULL,
`f_moduleItem_id` int(11) NOT NULL,
`userItem_value` varchar(255) DEFAULT NULL,
PRIMARY KEY (`f_user_id`,`f_moduleItem_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=35 ;