本篇內(nèi)容介紹了“MySQL中的join、left join和right join的用法”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)建站專注于郁南網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供郁南營(yíng)銷型網(wǎng)站建設(shè),郁南網(wǎng)站制作、郁南網(wǎng)頁(yè)設(shè)計(jì)、郁南網(wǎng)站官網(wǎng)定制、重慶小程序開發(fā)服務(wù),打造郁南網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供郁南網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。
暫時(shí)先用兩個(gè)表來演示:
創(chuàng)建bro_cats表:
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()
);
創(chuàng)建bro_articles表:
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)
);
接下來我們向里邊插入數(shù)據(jù)
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’);
INSERT INTO bro_articles(cid, name, content) //php 類中 cid=1
values(1,’this article of php1’, ‘php content1’);
INSERT INTO bro_articles(cid, name, content) //php 類中 cid=1
values(1,’this article of php2’, ‘php content2’);
INSERT INTO bro_articles(cid, name, content) // 類中 cid=2
values(2,’this article of jsp’, ‘jsp content’);
INSERT INTO bro_articles(cid, name, content) //asp 類中 cid=3
values(3,’this article of asp1’, ‘asp content1’);
INSERT INTO bro_articles(cid, name, content) //asp 類中 cid=3
values(3,’this article of asp2’, ‘asp content2’);
下一步我們就用join語(yǔ)句測(cè)試一下
左聯(lián)接: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;
右聯(lián)接: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;
聯(lián)接: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;
具體的這三個(gè)是什么效果,我還是建議大家試一下比較一下自己得出結(jié)論。
“mysql中的join、left join和right join的用法”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!