0
 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 的所有数据。

4

1 回答 1

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
于 2013-02-12T10:26:25.913 回答