【发布时间】:2015-06-27 04:52:03
【问题描述】:
我想在我正在进行的项目中从数据库中获取记录。
我有 5 张桌子;每个人都制作保存在起始四个表中的配置文件,然后定义合作伙伴配置文件。我想获取所有符合个人资料的合作伙伴名称。
这是我的表格结构:
Basic Info (reg_id, name, gender, dob, martial_status)
Education (id,reg_id,education,college)
Location (id,reg_id,country,state, city)
Other_details (id,reg_id,height, weight)
Partner (id, reg_id, gender, dob, education, college, country, state, city, height, weight,martial_status) [ This is the Main Table]..
到目前为止,我尝试了这个但没有运气:
SELECT `basic_info`.`reg_id`,
`basic_information`.`dob`,
`other_detail`.`height`,
`location`.`city`,
`education`.`education`
FROM `basic_information`
INNER JOIN(
SELECT *
FROM `patner`
WHERE `patner`.`reg_id`='shi01') `patner`
ON `basic_information`.`martial_status`=`partner`.`martial_status`
AND `basic_information`.`reg_id`!='shi01'
INNER JOIN `education`
ON `patner`.`education`=`education`.`education`
AND `patner`.`education`=`education`.`education`
INNER JOIN `location`
ON `patner`.`city`=`location`.`city`
INNER JOIN `other_detail`
ON `patner`.`bodytype`=`other_detail`.`body_type`
AND `patner`.`skin`=`other_detail`.`skin`
AND `patner`.`height1` <= `other_detail`.`height`
GROUP BY `basic_information`.`reg_id`;
【问题讨论】:
-
请提供表格定义。表中的主键和外键是什么。 ?
-
在第一个表中 Reg_id 是 PK.. 在 Rest 中是 FK..