社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
⦁ 内链接关联查询:
如果表A和表B有一个外键关联 ,可以通过外键进行内链接查询
select dictinfo.*, dicttype.typename
from dictinfo, dicttype
where dictinfo.typecode = dicttype.typecode
--不通过外键,通过groupid查询 用户类型的代码结果集,只能查询出一条记录,可以使用内链接select sysuser.*, dictinfo.info
from sysuser,
(select dictcode, typecode, info from dictinfo where typecode = 's01') dictinfo
where sysuser.groupid = dictinfo.dictcode
select sysuser.*
from sysuser, (select dictcode, typecode, info from dictinfo) dictinfo
where sysuser.groupid = dictinfo.dictcode
select sysuser.*,useryy.mc from sysuser left join useryy on sysuser.sysid = useryy.id
select * from useryy right join sysuser on sysuser.sysid = useryy.id
--以上的需要不能使用内链接select sysuser.*,useryy.mc from sysuser, useryy where sysuser.sysid = useryy.id
小结:select sysuser.*,
(select * from useryy where id = sysuser.sysid)
from sysuser
子查询只能返回一列,否则 :
正确的sql:
--子查询
--根据sysid取出单位名称
--根据groupid查询用户类型代码对应的名称
select sysuser.*,
(select mc from useryy where id = sysuser.sysid)sysmc,
(select info from dictinfo where dictcode = sysuser.groupid and typecode = 's01')groupname
from sysuser
select * from
(
select * from(
select * from (
) A
) B
) C;
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!