Oracle connection Query

Source: Internet
Author: User
I have been confused about internal connections, left connections, left outer connections, right connections, right outer connections, and full connections. I have created two tables by myself, write an SQL statement to check whether the left connection and the left outer connection are the same, and the right connection and the right outer connection are the same. A guy once showed me what the left connection is like, and the left outer connection is

I have been confused about internal connections, left connections, left outer connections, right connections, right outer connections, and full connections. I have created two tables by myself, write an SQL statement to check whether the left connection and the left outer connection are the same, and the right connection and the right outer connection are the same. A guy once showed me what the left connection is like, and the left outer connection is

I have been confused about internal connections, left connections, left outer connections, right connections, right outer connections, and full connections. I have created two tables by myself, write an SQL statement to check whether the left connection and the left outer connection are the same, and the right connection and the right outer connection are the same. A guy once showed me what the left connection was like, and the left outer connection was like that. What I said was mysterious and confused. Test it by yourself and find that it is the same as that. It is more convincing to use the results.

Note: No left inner connection or right inner connection exists. (if the test is performed, an error is returned, indicating that these connections do not exist)


Create a student table

create table STUDENT(  ID      NUMBER(5),  NAME    VARCHAR2(20),  CLAZZID NUMBER(5))

Insert some records



Create a clazz table

create table CLAZZ(  ID   NUMBER(5),  NAME VARCHAR2(50))
Insert some records


Query the Student name and Class Name

-- Common mode. The connection mode is not specified. The select s is connected internally by default. id sid, s. name, c. id cid, c. name class name from student s, clazz c where s. clazzid = c. id; -- equivalent to select s. id sid, s. name, c. id cid, c. name class name from student s inner join clazz c on s. clazzid = c. id;


-- Left (outer) join. The left table is used as the base table. The number of records in the result set is equal to or greater than the number of records in the base table. select s. id sid, s. name, c. id cid, c. name class name from student sleft outer join clazz c on s. clazzid = c. id; -- or use left outer join, the results are the same -- available in oracle + select s. id sid, s. name, c. id cid, c. name class name from student s, clazz c where s. clazzid = c. id (+); -- + is located in clazz. student is used as the base table.


-- Right (outer) join. The right table is used as the base table. The number of records in the result set is equal to or greater than the number of records in the base table. select s. id sid, s. name, c. id cid, c. name class name from student sright join clazz c on s. clazzid = c. id; ---- or use right outer join, the results are the same -- available in oracle + select s. id sid, s. name, c. id cid, c. name class name from student s, clazz c where s. clazzid (+) = c. id; -- + indicates that the clazz is used as the base table.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.