Database paradigm (three kinds)
Associated with the query:
1 external links :
(1) left external link
(2) connected to the right outer
(3) fully connected
2 the connection:
create table T_class(
classid integer primary key,
className varchar2(255),
studentcount integer
)
insert INTO T_class
values
(5 'class 5', 56)
CREATE table T_student(
stuid integer primary key,
stuName varchar2(255),
stuScore float,
classid integer
)
INSERT INTO t_student(stuid,stuName,stuScore)
values
(5, 'Hsiao Ming', 88)
- After insertion, no one class 5, Xiaoming no class: Let's start inquiry
- When we inquire student information, if you would like to inquire where his class information, we need to associate these two tables together, is our: associated with the query
select * FROM T_class
select * FROM t_student
- outer join (left outer join, right outer join, fully connected)
- left outer: left and join by keyword, the left key is left represents the main table, the right is the schedule, whether the id is on both sides does not correspond,
- the primary table information is displayed, showing only the schedule corresponding to the data ID can be up, not associated with each other are shown as null data
select * FROM t_student t1 LEFT JOIN t_class c1 on t1.classid=c1.classid
- left outer join another way:
select * FROM t_student t1, t_class c1 WHERE t1.classid= c1.classid(+)
- right outer join: The right and join keywords, right represents the right keywords is the main table, left Schedule
select * FROM t_student t1 RIGHT join t_class c1 ON t1.classid=c1.classid
- right outer join another way:
select * FROM t_student t1,t_class c1 where t1.classid(+)=c1.classid
- Full connection: connection through full and join keywords, the equivalent of two tables are the main table, all of the information display, full connection is not shorthand
select * FROM t_student t1 full join t_class c1 on t1.classid=c1.classid
- The above embodiment showed two classid, the following methods can customize the display content
select t1.*,c1.className,c1.studentcount FROM t_student t1 full join t_class c1 on t1.classid=c1.classid
- the connection: only two tables can query data by associating id (both are equivalent schedule)
select * FROM t_student t1 inner join t_class c1 on t1.classid=c1.classid
- In connection shorthand:
select * FROM t_student t1, t_class c1 WHERE t1.classid= c1.classid