CREATE TABLE `entity1` (
`entity_id` varchar(20) NOT NULL DEFAULT '',
`name` varchar(20) ,
`version` varchar(20) ,
PRIMARY KEY (`entity_id`));
CREATE TABLE `ent_att` (
`att_id` varchar(20) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL,
`valu` varchar(20) NOT NULL DEFAULT '',
PRIMARY KEY (`valu`),
FOREIGN KEY (`att_id`) REFERENCES `entity1` (`entity_id`));
CREATE TABLE `perf` (
`ent_id` varchar(20) ,
`state` varchar(20) ,
`status` varchar(20) ,
`perf_id` varchar(20) ,
FOREIGN KEY (`ent_id`) REFERENCES `entity1` (`entity_id`));
第一个表主键是其他两个表的外键, 我想从所有表中检索entity_id的所有数据。
答案 0 :(得分:1)
试试这个:
select et.entity_id,et.name,et.version,
ett.name as ent_att_name,ett.valu,pf.state,pf.perf_id,pf.status from entity1 et
inner join ent_att ett
on et.entity_id=ett.att_id
inner join perf pf
on et.entity_id=pf.ent_id