mysql4.1可嵌套多个查询
一、内连接查询
(1)delect bookid ,borrowTime,backTime,ifbak,bookname,author,price
from tb_borrow,tb_bookinfo where tb_borrow.bookid=tb_bookinfo.id;
二、子查询
(1)带in或not in
select id,bookname,author
from tb_bookinfo where id in(select bookid from tb_borrow);
(2)带比较运算符的子查询
(1)select score from tb_grade where name='优秀';
(2)select * from tb_student
where score >= (select score from tb_grade where name='优秀')
(3)带exists (not exists)
使用exist是关键字,内层查询语句不返回查询记录,而是返回一个真假值。返回真时:外层查询语句继续查询,返回false:外层查询不做任何查询或查不出任何记录;
select id,bookname,author,price from tb_bookinfo
where exists (select * from tb_borrow where tb_borrow.bookid=tb_bookinfo.id);
(4)any 或all
列名 比较运算符 any(子查询)
select * from tb_student1
where score > any(select score from tb_student1 where classid=13);