MySQL database outside connection, internal connection, natural connection

Source: Internet
Author: User

CREATE TABLE Join_teacher (
ID int primary KEY auto_increment,
T_name varchar (TEN) is not NULL,
Gender enum (' Male ', ' female ', ' secret ') not NULL
) engine InnoDB character set UTF8;
INSERT INTO join_teacher values
(1, ' Han Xin ', ' Male '),
(2, ' Li Bai ', ' Male '),
(3, ' Han Fei zi ', ' secret ');

CREATE TABLE Join_class (
ID int primary KEY auto_increment,
C_name varchar (TEN) is not NULL,
root int not nclass values
(1, ' php0115 ', 207),
(2, ' php0115 ', 207),
(3, ' php0115 ', 207);

CREATE TABLE Join_day (
ID int primary KEY auto_increment,
t_id int NOT NULL,
C_ID int NOT NULL,
Days tinyint NOT NULL,
Begin_date date NOT NULL,
End_date date NOT NULL
) engine InnoDB character set UTF8;
INSERT INTO join_day values
(1,1,1,15,20130115,20130220),
(2,2,2,20,20130222,20130325),
(3,3,3,15,20130327,20130418);

Tbl_left INNER JOIN tbl_right on join condition
INNER JOIN
Select Join_teacher.t_name,join_teacher.gender,join_day.begin_date,join_day.end_date
From Join_teacher inner join Join_day on
join_teacher.id=join_day.t_id;

SELECT * FROM Join_teacherINNER JOINJoin_day on
join_teacher.id=join_day.t_id;

Leftouter JOIN
SELECT * FROM join_teacher LEFT outer join Join_day on
join_teacher.id=join_day.t_id;
Join connection query: Connect records from multiple tables

Category: Inner connection, outer connection, natural connection
Internal connection: The connection within the data, requires that multiple connected data must exist in order to connect
Outer joins: If one or more of the data that is responsible for the connection does not exist, it is called an outer join


Select s.*,si.* from Info_class as CLeft joinInfo_student as S on c.id=s.class_id
Left joinInfo_student_info as Si on s.id=si.id where c.class_name= ' php0331 ';

Select child.* from Hd_cate as the parent left join Hd_cate as child on Child.pid=parent.id where parent.name= ' MySQL ';

Format:
SELECT * FROM table1
Left join Table2 on condition
Left join Table3 on condition
......
Add information by column ull
) engine InnoDB character set UTF8;
INSERT INTO Join_

MySQL database outside connection, internal connection, natural connection

Related Article

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.