Home > Database > Mysql Tutorial > body text

oracle中复杂sql查询语句详解 (1/4)

WBOY
Release: 2016-06-07 17:45:44
Original
1181 people have browsed it

1.查询语句的使用
使用 select语句和子查询(subquery)可以从一个或多个表,视图,实体试图中返回数据.
 
1.1相关子查询
可以将子查询(as subquery)或in或exists当成where的一个条件的一部分,这样的查询称为子查询
  .where中可以包含一个select语句的子查询
  .where中可以包含in,exists语句
  .最多可以嵌套16层
  .层次过多会影响性能
  [例]简单子查询实例
  查询是否有的专家既以研究所的名义来申请基金项目,又以大学系为单位申请项目
  (按规定只能以一个单位来申请)
  sql> create table univ_subject
  2    (
  3       name                 varchar2(12) not null,
  4       per_id                number     not null,
  5      dept_name       varchar2(20)            
  6    );
  sql> insert into univ_subject  values('gaoqianjing',1001,'信息工程系');
  sql> insert into univ_subject  values('wangbing',1002,'物理系');
  sql> insert into univ_subject  values('liming',1003,'化学系');
  ===============
   sql> create table  colle_subject
  2     (
  3              colle_name    varchar2(20),
  4              per_id              number
  5     );
  sql> insert into colle_subject values('电子研究所',1001);
  sql>  insert into colle_subject values('物理研究所',1005);
  ================
  sql> select name,per_id,dept_name from univ_subject where per_id in
  2    (select per_id from colle_subject);

  name            per_id   dept_name
  ------------          ---------     --------------------
  gaoqianjing  1001      信息工程系

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!