My_Project

资料整理


SQL语句-特殊查询语句

<p>1、嵌套</p> <pre><code>说明:一个语句嵌套在另一个语句中。 select * from 表 where 字段 in (select 字段 from 表名 where 条件) and 条件;</code></pre> <p>2、关联</p> <pre><code>说明:两个表关联条件成立才会将这条记录展示出来。 select * from 表1,(select 字段,字段2 from 表 where 条件)表2 where 表1.字段=表2.字段 and 条件; select * from 表1,表2 where 表1.字段=表2.字段 and 条件; 1.找出关联条件,即:有关系字段 2.展示字段 3.找出过滤条件 例:展示李四的学生信息和考试科目成绩: select * from student1,score where student1.id=score.stu_id and student1.name='李四';</code></pre> <p>3、多表连接</p> <pre><code>left join 左连接:将左表中的信息全部展示出来 select * from s left join sc on s.sno=sc.sno where 条件; right join 右连接:将右表中的信息全部展示出来 select * from s right join sc on s.sno=sc.sno where 条件; inner join 内连接:将条件成立的信息展示出来 select * from s inner join sc on s.sno=sc.sno where 条件;</code></pre>

页面列表

ITEM_HTML