When I checked the brophp framework today, I conveniently reviewed the combined query in mysql. (In the past, I would use the simplest "select * from..."). Others do not dare to use them as much as they do. I am cleaning out the "blind spots" in the past.
Next, let's talk about the simple joint query. Of course, we have to create several database tables first. I'm limited. I will use two tables for demonstration at the moment:
Create a 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 a bro_articles 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 will 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 ', 'asp demo ');
Insert into bro_articles (cid, name, content) // cid = 1 in the php class
Values (1, 'This article of php1', 'php content1 ');
Insert into bro_articles (cid, name, content) // cid = 1 in the php class
Values (1, 'This article of php2 ', 'php content2 ');
Insert into bro_articles (cid, name, content) // cid = 2 in the jsp class
Values (2, 'This article of jsp ', 'jsp content ');
Insert into bro_articles (cid, name, content) // cid = 3 in asp class
Values (3, 'This article of asp1', 'asp content1 ');
Insert into bro_articles (cid, name, content) // cid = 3 in asp class
Values (3, 'This article of asp2 ', 'asp content2 ');
Next, we will test it using 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 join: 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;
Join: 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 items? I suggest you try and compare them to draw a conclusion.
In the future, multiple table queries will be extended, and how to optimize multi-table queries. Welcome to my blog !! I remember reading the reply amount. I hope you will correct me if there is something wrong. After all, it's a cainiao and you have to learn from the old birds !!!
Author "You_Can"