Get the App
SLTechnology News&Howtos  ›  Database  › 

The usage of join, left join and right join in mysql

Shulou Source: shulou.com Published: 2022-05-31 18:00:24 09月16日 Update

This article introduces the knowledge of "the usage of join, left join and right join in mysql". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

For the time being, we will demonstrate with two tables:

Create the bro_ cats table:

Create table bro_cats (

Id int (11) not null auto_increment

Name varchar (128) not null default'

Desn varchar (128) not null default'

Primary key ()

);

Create the bro_ artifacts table:

Create table bro_articles (

Id int not null auto_increment

Cid int not null

Name varchar (128) not null

Content test not null

Primary key (id)

);

Next, we insert data into it.

INSERT INTO bro_cats (name, desn) values ('php','php demo')

INSERT INTO bro_cats (name, desn) values ('jsp','jsp demo')

INSERT INTO bro_cats (name, desn) values ('', 'asp demo')

Cid=1 in INSERT INTO bro_articles (cid, name, content) / / php class

Values (1) this article of php1', 'php content1')

Cid=1 in INSERT INTO bro_articles (cid, name, content) / / php class

Values (1) this article of php2', 'php content2')

INSERT INTO bro_articles (cid, name, content) / / cid=2 in class

Values (2) this article of jsp', 'jsp content')

Cid=3 in INSERT INTO bro_articles (cid, name, content) / / asp class

Values (3 million this article of asp1', 'asp content1')

Cid=3 in INSERT INTO bro_articles (cid, name, content) / / asp class

Values (3 million this article of asp2', 'asp content2')

Next, let's test it with the join statement.

Left join: left join

Select bro_cats.name as catsname,bro_cats.desn as description,bro_articles.name as articlesname,bro_articles.content as articlecontent from bro_cats left join bro_articles on bro_cats.id = bro_articles.cid

Right connection: right join

Select bro_cats.name as catsname,bro_cats.desn as description,bro_articles.name as articlesname,bro_articles.content as articlecontent from bro_cats right join bro_articles on bro_cats.id = bro_articles.cid

Connection: join

Select bro_cats.name as catsname,bro_cats.desn as description,bro_articles.name as articlesname,bro_articles.content as articlecontent from bro_cats join bro_articles on bro_cats.id = bro_articles.cid

What are the specific effects of these three? I suggest you try and compare yourself to come to a conclusion.

This is the end of the introduction to "the use of join, left join and right join in mysql". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Next content more knowledge practicality learning achievement three two dilemma reality suggestion situation effect data article case conclusion editing website industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn MySQL Shulou Technology Microsoft