- 浏览: 1153381 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (411)
- Java Foundation (41)
- AI/机器学习/数据挖掘/模式识别/自然语言处理/信息检索 (2)
- 云计算/NoSQL/数据分析 (11)
- Linux (13)
- Open Source (12)
- J2EE (52)
- Data Structures (4)
- other (10)
- Dev Error (41)
- Ajax/JS/JSP/HTML5 (47)
- Oracle (68)
- FLEX (19)
- Tools (19)
- 设计模式 (4)
- Database (12)
- SQL Server (9)
- 例子程序 (4)
- mysql (2)
- Web Services (4)
- 面试 (8)
- 嵌入式/移动开发 (18)
- 软件工程/UML (15)
- C/C++ (7)
- 架构Architecture/分布式Distributed (1)
最新评论
-
a535114641:
LZ你好, 用了这个方法后子页面里的JS方法就全不能用了呀
页面局部刷新的两种方式:form+iframe 和 ajax -
di1984HIT:
学习了,真不错,做个记号啊
Machine Learning -
赵师傅临死前:
我一台老机器,myeclipse9 + FB3.5 可以正常使 ...
myeclipse 10 安装 flash builder 4.6 -
Wu_Jiang:
触发时间在将来的某个时间 但是第一次触发的时间超出了失效时间, ...
Based on configured schedule, the given trigger will never fire. -
cylove007:
找了好久,顶你
Editable Select 可编辑select
http://superman-chenzs.itpub.net/post/29327/276049
笛卡尔积:
cross join
Join Types:
1. Inner Join
- Equal-Join
- Non-Equal-Join
2. Outer Join
- Left-Outer-Join
- Right-Outer-Join
3. Self Join
- Join a table to itself
- Using the table's alias name to complete the self join.
- attention the repeat lines
-----------------------------------------------------------------------------------------------------------------
Joining Tables Using Oracle Syntax:
- Write the join condition in the WHERE clause.
- Prefix the column name with the table name when the same column name appears in more than one table.
- Additional Search Conditions Using the AND Operator
- To join n tables together,you need a minimun of n-1 join conditions.
-----------------------------------------------------------------------------------------------------------------
Qualifying Ambiguous Column Names:
- Use table prefixes to qualify column names that are in multiple tables.
- Improve performance by using table prefixes.
- Distinguish columns that have identical names but reside in different tables by using column aliases.
-----------------------------------------------------------------------------------------------------------------
Outer Join:
- You use an outer join to also see rows that do not meet the join condition.
- The Outer join operator is the plus sign (+).
- The sign '(+)' is on the ritht,the type is Left-Outer-Join
- The sign '(+)' is on the left ,the type is Right-Outer-Join
eg:
----------------------------------
the Right-Outer-Join:
--->
select empno,ename,d.deptno
from emp e,dept d
where e.deptno(+) = d.deptno
EMPNO ENAME DEPTNO
---------- ---------- ----------
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10
40
----------------------------------
the Left-Outer-Join:
--->
select empno,ename,d.deptno
from emp e, dept d
where e.deptno = d.deptno(+);
EMPNO ENAME DEPTNO
--------- ---------- ----------
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10
**********************************************************************************************************************
Joining Tables Using SQL: 1999 Syntax
Syntax:
SELECT table1.column,table2.column
FROM table1
[CROSS JOIN table2] |
[NATURAL JOIN table2] |
[JOIN table2 USING (column_name)] |
[JOIN table2 ON(table1.column_name = table2.column_name)] |
[LEFT|RIGHT|FULL OUTER JOIN table2 ON (table1.column_name = table2.column_name)] ;
-----------------------------------------------------------------------------------------------------------------------
Creating Cross Joins:
- The CROSS JOIN clause produces the cross-product of two tables.
- This is the same as a Cartesian product between the two tables.(迪卡尔集)
eg:
select empno,ename,d.deptno from emp e CROSS JOIN dept d;
===
select empno,ename,d.deptno from emp e,dept d;
-----------------------------------------------------------------------------------------------------------------------
Creating Natural Joins:
- The NATURAL JOIN clause is based on all columns in the two tables that have the same name.
- It selects rows from the two tables that have equal values in all matched columns.
- If the columns having the same names have different data types,an error is returned.
- Do not use a table name or alias in the referenced columns.
eg:
select empno,ename,deptno from emp NATURAL JOIN dept;
===
SELECT empno,ename,d.deptno from emp e,dept d where e.deptno=d.deptno;
-----------------------------------------------------------------------------------------------------------------------
Creating Join with the USING Clause:
- If several columns have the same names but the data types do not match,the NATURAL JOIN clause can be modified with the USING clause to specify the columns that should be used for an equijoin.
- Use the USING clause to match only one column when more than one column matches.
- Do not use a table name or alias in the referenced columns.
- The NATURAL JOIN and USING clauses are mutually exclusive(相互排斥).
-----------------------------------------------------------------------------------------------------------------------
Creating Joins with the ON Clause:
- The join condition for the natural join is basically an equijoin of all columns with the same name.
- To specify arbitrary(任意的) conditions or specify columns to join ,the ON clause is used.
- The join condition is separated from other search conditions.
- The ON clause makes code easy to understand.
eg:
select e.empno,e.ename,d.deptno from emp e join dept d on e.deptno=d.deptno;
===
select e.empno,e.ename,d.deptno from emp e ,dept d where e.deptno=d.deptno;
- Creating Three-Way Joins with the ON Clause,eg:
------
SELECT employee_id,city,department_name
FROM employees e
JOIN departments d ON d.department_id=e.department_id
JOIN locations l ON d.location_id=l.location_id;
- that means N JOINS must have N-1 join_conditions.
-----------------------------------------------------------------------------------------------------------------------
INNER JOIN & OUTER JOIN:
- In SQL:1999, the join fo two tables returning only matched rows is an inner join.
- A join between two tables that returns the results of the inner join as well as unmatched rows left (or right) tables is a left (or right) outer join.
- A join between two tables that returns the results of an inner join as well as the results of a left and right join is a full outer join.
- The Left-Outer-Join: show all the value in the leftside table, even the rightside's value is null.
- The Right-Outer-Join: show all the value in the rightside table, even the leftside's value is null.
--------
eg:
--------
LEFT JOIN:
select ename,d.deptno from emp e left outer join dept d ON e.deptno=d.deptno;
===
select ename,d.deptno from emp e ,dept d where e.deptno=d.deptno(+);
ENAME DEPTNO
---------- ----------
SMITH 20
ALLEN 30
WARD 30
JONES 20
MARTIN 30
BLAKE 30
CLARK 10
SCOTT 20
KING 10
TURNER 30
ADAMS 20
JAMES 30
FORD 20
MILLER 10
已选择14行
--------
RIGHT JOIN:
select ename,d.deptno from emp e RIGHT OUTER JOIN dept d ON e.deptno=d.deptno;
===
select ename,d.deptno from emp e,dept d where e.deptno(+)=d.deptno;
ENAME DEPTNO
---------- ----------
SMITH 20
ALLEN 30
WARD 30
JONES 20
MARTIN 30
BLAKE 30
CLARK 10
SCOTT 20
KING 10
TURNER 30
ADAMS 20
JAMES 30
FORD 20
MILLER 10
40
已选择15行
--------
FULL OUTER JOIN:
select ename,d.deptno from emp e FULL OUTER JOIN dept d ON e.deptno=d.deptno;
ENAME DEPTNO
---------- ----------
SMITH 20
ALLEN 30
WARD 30
JONES 20
MARTIN 30
BLAKE 30
CLARK 10
SCOTT 20
KING 10
TURNER 30
ADAMS 20
JAMES 30
FORD 20
MILLER 10
40
笛卡尔积:
cross join
Join Types:
1. Inner Join
- Equal-Join
- Non-Equal-Join
2. Outer Join
- Left-Outer-Join
- Right-Outer-Join
3. Self Join
- Join a table to itself
- Using the table's alias name to complete the self join.
- attention the repeat lines
-----------------------------------------------------------------------------------------------------------------
Joining Tables Using Oracle Syntax:
- Write the join condition in the WHERE clause.
- Prefix the column name with the table name when the same column name appears in more than one table.
- Additional Search Conditions Using the AND Operator
- To join n tables together,you need a minimun of n-1 join conditions.
-----------------------------------------------------------------------------------------------------------------
Qualifying Ambiguous Column Names:
- Use table prefixes to qualify column names that are in multiple tables.
- Improve performance by using table prefixes.
- Distinguish columns that have identical names but reside in different tables by using column aliases.
-----------------------------------------------------------------------------------------------------------------
Outer Join:
- You use an outer join to also see rows that do not meet the join condition.
- The Outer join operator is the plus sign (+).
- The sign '(+)' is on the ritht,the type is Left-Outer-Join
- The sign '(+)' is on the left ,the type is Right-Outer-Join
eg:
----------------------------------
the Right-Outer-Join:
--->
select empno,ename,d.deptno
from emp e,dept d
where e.deptno(+) = d.deptno
EMPNO ENAME DEPTNO
---------- ---------- ----------
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10
40
----------------------------------
the Left-Outer-Join:
--->
select empno,ename,d.deptno
from emp e, dept d
where e.deptno = d.deptno(+);
EMPNO ENAME DEPTNO
--------- ---------- ----------
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10
**********************************************************************************************************************
Joining Tables Using SQL: 1999 Syntax
Syntax:
SELECT table1.column,table2.column
FROM table1
[CROSS JOIN table2] |
[NATURAL JOIN table2] |
[JOIN table2 USING (column_name)] |
[JOIN table2 ON(table1.column_name = table2.column_name)] |
[LEFT|RIGHT|FULL OUTER JOIN table2 ON (table1.column_name = table2.column_name)] ;
-----------------------------------------------------------------------------------------------------------------------
Creating Cross Joins:
- The CROSS JOIN clause produces the cross-product of two tables.
- This is the same as a Cartesian product between the two tables.(迪卡尔集)
eg:
select empno,ename,d.deptno from emp e CROSS JOIN dept d;
===
select empno,ename,d.deptno from emp e,dept d;
-----------------------------------------------------------------------------------------------------------------------
Creating Natural Joins:
- The NATURAL JOIN clause is based on all columns in the two tables that have the same name.
- It selects rows from the two tables that have equal values in all matched columns.
- If the columns having the same names have different data types,an error is returned.
- Do not use a table name or alias in the referenced columns.
eg:
select empno,ename,deptno from emp NATURAL JOIN dept;
===
SELECT empno,ename,d.deptno from emp e,dept d where e.deptno=d.deptno;
-----------------------------------------------------------------------------------------------------------------------
Creating Join with the USING Clause:
- If several columns have the same names but the data types do not match,the NATURAL JOIN clause can be modified with the USING clause to specify the columns that should be used for an equijoin.
- Use the USING clause to match only one column when more than one column matches.
- Do not use a table name or alias in the referenced columns.
- The NATURAL JOIN and USING clauses are mutually exclusive(相互排斥).
-----------------------------------------------------------------------------------------------------------------------
Creating Joins with the ON Clause:
- The join condition for the natural join is basically an equijoin of all columns with the same name.
- To specify arbitrary(任意的) conditions or specify columns to join ,the ON clause is used.
- The join condition is separated from other search conditions.
- The ON clause makes code easy to understand.
eg:
select e.empno,e.ename,d.deptno from emp e join dept d on e.deptno=d.deptno;
===
select e.empno,e.ename,d.deptno from emp e ,dept d where e.deptno=d.deptno;
- Creating Three-Way Joins with the ON Clause,eg:
------
SELECT employee_id,city,department_name
FROM employees e
JOIN departments d ON d.department_id=e.department_id
JOIN locations l ON d.location_id=l.location_id;
- that means N JOINS must have N-1 join_conditions.
-----------------------------------------------------------------------------------------------------------------------
INNER JOIN & OUTER JOIN:
- In SQL:1999, the join fo two tables returning only matched rows is an inner join.
- A join between two tables that returns the results of the inner join as well as unmatched rows left (or right) tables is a left (or right) outer join.
- A join between two tables that returns the results of an inner join as well as the results of a left and right join is a full outer join.
- The Left-Outer-Join: show all the value in the leftside table, even the rightside's value is null.
- The Right-Outer-Join: show all the value in the rightside table, even the leftside's value is null.
--------
eg:
--------
LEFT JOIN:
select ename,d.deptno from emp e left outer join dept d ON e.deptno=d.deptno;
===
select ename,d.deptno from emp e ,dept d where e.deptno=d.deptno(+);
ENAME DEPTNO
---------- ----------
SMITH 20
ALLEN 30
WARD 30
JONES 20
MARTIN 30
BLAKE 30
CLARK 10
SCOTT 20
KING 10
TURNER 30
ADAMS 20
JAMES 30
FORD 20
MILLER 10
已选择14行
--------
RIGHT JOIN:
select ename,d.deptno from emp e RIGHT OUTER JOIN dept d ON e.deptno=d.deptno;
===
select ename,d.deptno from emp e,dept d where e.deptno(+)=d.deptno;
ENAME DEPTNO
---------- ----------
SMITH 20
ALLEN 30
WARD 30
JONES 20
MARTIN 30
BLAKE 30
CLARK 10
SCOTT 20
KING 10
TURNER 30
ADAMS 20
JAMES 30
FORD 20
MILLER 10
40
已选择15行
--------
FULL OUTER JOIN:
select ename,d.deptno from emp e FULL OUTER JOIN dept d ON e.deptno=d.deptno;
ENAME DEPTNO
---------- ----------
SMITH 20
ALLEN 30
WARD 30
JONES 20
MARTIN 30
BLAKE 30
CLARK 10
SCOTT 20
KING 10
TURNER 30
ADAMS 20
JAMES 30
FORD 20
MILLER 10
40
发表评论
-
Oracle: minus | in | exists
2012-09-05 13:49 1498解释及例子: MINUS Query: http://www. ... -
一个奇怪的Oracle sql问题
2011-01-13 16:13 1373select A.M,B.N from Table1 A ... -
Oracle Analytic Functions:RANK, DENSE_RANK, FIRST and LAST;PARTITION BY
2010-12-13 17:02 1325Oracle/PLSQL: Rank Function: ht ... -
Oracle Analytic Functions:RANK, DENSE_RANK, FIRST and LAST
2010-12-13 17:02 1272Oracle/PLSQL: Rank Function: ht ... -
Oracle:Collections Records Type %TYPE %ROWTYPE
2010-11-09 22:27 1275PL/SQL Collections and Records: ... -
Oracle Cursor 游标
2010-11-09 20:44 3054Oracle中Cursor介绍: http://www.ite ... -
Oracle 锁机制
2010-09-19 20:12 3729Oracle多粒度封锁机制研究: http://www.itp ... -
Oracle Data Dictionary 数据字典
2010-09-19 16:44 1551Oracle数据字典查阅: http://download.o ... -
Oracle Sign Function
2010-09-17 14:52 1470Oracle/PLSQL: Sign Function: ht ... -
Oracle Built-In Functions: Next_Day and Last_Day
2010-09-16 17:09 1546next_day(date,char): 它用来返回从第一个 ... -
Oracle Procedure 存储过程
2010-09-16 08:36 1368Oracle/PLSQL: Creating Procedur ... -
Oracle Exception Handle 异常处理
2010-09-15 13:00 2099Handling PL/SQL Errors: http:// ... -
Oracle 性能工具 : Explain plan、Autotrace、Tkprof
2010-09-14 18:07 2238Oracle: 三个内置的性能工具包 Explain plan ... -
关于Oracle数据和对象的导入导出 [转]
2010-09-14 10:25 1279关于Oracle数据和对象的导入导出 [转]: http:// ... -
Oracle jobs(DBMS_JOB and DBMS_SCHEDULER)
2010-07-21 14:14 7842写PL/SQL procedure的时候,一定要写的够健壮、够 ... -
Oracle 各种注释
2010-07-20 14:19 3667为SQL语句添加注释: http://do ... -
Oracle 监听 本地Net服务名 配置
2010-07-20 10:32 1329Oracle数据库配置: http://shupili1410 ... -
[Oracle]Difference between a database and an instance(数据库 实例 区别)
2010-07-20 09:31 1508Difference between a database a ... -
Oracle Bulk Collect
2010-07-16 10:03 1380On BULK COLLECT: http://www.ora ... -
Oracle/PLSQL: FOR Loop 循环语句
2010-07-15 16:43 9366Oracle/PLSQL: FOR Loop: http:// ...
相关推荐
Oracle SQL是数据库管理中不可或缺的一部分,它用于在Oracle数据库中执行数据查询和操作。本系列“Oracle SQL:经典查询练手四篇”旨在通过一系列实际的查询示例,帮助用户提高对SQL语言的理解和应用能力。 在第一...
在SQL查询中,JOIN操作是连接两个或多个表的关键部分,用于从这些表中提取相关数据。本篇文章将深入探讨LEFT JOIN、RIGHT JOIN以及INNER JOIN的用法,并通过实例进行对比,帮助理解它们之间的差异。 1. LEFT JOIN...
4. **JOIN**: 尽管JSON结构不支持传统SQL的表连接,但JsonSQL可以通过嵌套查询实现类似的效果。例如,如果你有包含用户和其订单的JSON,可以使用嵌套查询来关联用户和他们的订单。 5. **GROUP BY** 和 **HAVING**: ...
SQL 连接 JOIN 例解
### SQL中JOIN的使用详解 在SQL查询语言中,`JOIN`操作是非常重要的一个部分,它主要用于合并两个或多个表中的数据。通过不同的`JOIN`类型,我们可以灵活地获取所需的组合数据。本文将详细介绍五种主要的`JOIN`类型...
* Right Join:以右表为基础,返回右表中的所有记录和左表中符合条件的记录。 * Inner Join:返回两个表中符合条件的记录,不以任何一方为基础。 例如,使用Right Join语句: ```sql SELECT * FROM A RIGHT JOIN B ...
标题《LINQ to SQL在行动:Join和Group-学习在.NET程序中编写数据访问功能的方法》指出了本文的核心内容,即探讨如何利用LINQ to SQL这一技术在.NET环境下实现数据访问功能,并详细解析了如何使用Join和Group操作来...
在SQL(Structured Query Language)中,JOIN操作是用于合并两个或更多个表的数据,以便根据它们之间的关联性创建更复杂的查询结果。JOIN是数据库查询中的关键部分,它允许我们在多个表之间建立联系,从而获取更丰富...
总之,查询一个人的信息在SQL中涉及到对多个表的联合查询,通过`JOIN`操作连接这些表,并使用`WHERE`子句来筛选特定的用户。随着业务需求的复杂性增加,查询语句也可能需要包含更多的功能,如分组、排序、过滤等。...
SQL join 完全用法 SQL join 完全用法 学习sql join
### SQL Server 中 DELETE 语句结合 INNER JOIN 的应用 #### 背景介绍 在数据库管理与维护过程中,经常会遇到需要删除表中的某些记录的情况。简单地使用 `DELETE` 语句可以删除单个表中的数据,但在多表关联的情况...
### SQL语句中JOIN的用法详解 在SQL查询语言中,`JOIN`是一个非常重要的概念,它允许我们从两个或多个表中提取数据。通过使用不同类型的JOIN操作,我们可以根据表之间的关系来灵活地组织数据。下面我们将详细介绍几...
LINQ to SQL语句之Join和Order By部分代码 语句描述:这个例子在From子句中使用外键导航筛选在西雅图的雇员,同时列出其所在地区。这条生成SQL语句为: SELECT [t0].[FirstName], [t0].[LastName], [t2]....
* LEFT OUTER JOIN:一个表满足条件的行,和另一个表的所有行。 * RIGHT OUTER JOIN:与 LEFT 相同,但两个表的角色互换。 * FULL OUTER JOIN:LEFT OUTER 和 RIGHT OUTER 中所有行的超集。 内连接(Inner Join) ...
Oracle SQL是数据库管理和数据分析的重要工具,尤其在处理Oracle数据库时不可或缺。本文提供的经典练习题旨在帮助初学者熟悉SQL语句的编写,特别是针对Oracle数据库特有的功能。以下将详细讲解涉及的知识点。 1. **...
在PL/SQL(Oracle数据库的编程语言)中,JOIN语法尤其重要,因为它是处理复杂查询的基础。以下是PL/SQL中不同类型的JOIN及其特点的详细分析: 1. **左连接(LEFT JOIN)**: 左连接返回左表(Aa)的所有行,即使在...
根据不同的需求,SQL提供了多种类型的JOIN,包括交叉JOIN、内JOIN、左外JOIN、右外JOIN和全外JOIN。以下是对这些JOIN类型的具体解释和示例。 1. **交叉JOIN (Cross JOIN)**: 交叉JOIN也称为笛卡尔积,它返回第一个...
### SQL经典语句详解 #### 一、数据库操作 **1. 创建数据库** SQL语言提供了`CREATE DATABASE`语句来创建一个新的数据库。这通常是在项目启动或数据库环境搭建初期执行的操作。 ```sql CREATE DATABASE ...
Oracle SQL是一种强大的数据库查询语言,尤其在处理结构化数据时,它的功能和灵活性深受数据库管理员和开发人员的喜爱。本主题将深入探讨Oracle SQL中的经典查询技巧,帮助你提升数据库操作的效率。 首先,理解SQL...
### SQL的INNER JOIN语法 #### 一、概念与作用 在SQL语言中,`INNER JOIN`是一种连接(Join)操作,用于从两个或多个表中提取数据,仅返回那些匹配的记录。简单来说,它会查找两个表中具有共同属性(如相同的键值...