mysql三表查询的方法(附图)

mysql三表查询的方法(附图)_第1张图片

 //建立tb_borrow与tb_reader间的视图 
create view tb_viewborreader as
select br.readerid,rd.name
from tb_borrow as br
left join tb_reader as rd on br.readerid=rd.id


 //建立tb_borrow,tb_bookcase与tb_bookinfo间的视图 
create view tb_viewbookiborrdcase as
select br.bookid,bc.jh
from tb_bookinfo as bi
left join tb_borrow as br on bi.id=br.bookid
join tb_bookcase as bc on bi.jhid=bc.jh


 //建立tb_borrow,tb_bookcase与tb_bookinfo间的视图 
create view tb_viewbookidborrtype as
select br.bookid,bt.typename
from tb_bookinfo as bi
left join tb_borrow as br on bi.id=br.bookid
join tb_booktype as bt on bi.typeid=bt.id

你可能感兴趣的:(数据库)