select p.ID, P.Name, p.GenderID, i.Name Gname ,P.EducationID
from T_PersonTest p , T_IdName i
where ( p.GenderID = i.ID and i.category='性别' )
或者
select p.ID, P.Name, p.GenderID, i.Name Ename ,P.EducationID
from T_PersonTest p , T_IdName i
where ( p.EducationID=i.ID and i.category='学历')
我觉得这种情况,这一张T_IdName表好难处理啊 作者: 郑丹丹1990 时间: 2013-4-9 12:26
查询多个表的数据的话,建议在数据库中建一个视图吧!作者: 史鹏飞 时间: 2013-4-9 15:17
select * from [员工表] as y ,T_IdName as N where y.EducationID = N.EducationID(T_IdName 表中的学历ID)
得到的就是两张表的数据作者: superjojo 时间: 2013-4-9 16:51
史鹏飞 发表于 2013-4-9 15:17
select * from [员工表] as y ,T_IdName as N where y.EducationID = N.EducationID(T_IdName 表中的学历ID ...
那如果我还要同时得到T_IdName 里的性别Name呢?
select p.ID, P.Name, p.GenderID, i.Name Gname ,P.EducationID
from T_PersonTest p , T_IdName i
where ( p.GenderID = i.ID and i.category='性别' )
select p.ID, P.Name, p.GenderID, i.Name Ename ,P.EducationID
from T_PersonTest p , T_IdName i
where ( p.EducationID=i.ID and i.category='学历')
select a.ID,a.Name,b.Name,b.ID,c.Name,c.ID from T_PersonTest as a
left join T_IdName as b on a.GenderID=b.ID
left join T_IdName as c on a.EducationID=c.ID