十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
本篇内容介绍了“MySQL中的join、left join和right join的用法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
创新互联建站专注于郁南网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供郁南营销型网站建设,郁南网站制作、郁南网页设计、郁南网站官网定制、重庆小程序开发服务,打造郁南网络公司原创品牌,更为您提供郁南网站排名全网营销落地服务。
暂时先用两个表来演示:
创建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()
);
创建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)
);
接下来我们向里边插入数据
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语句测试一下
左联接: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
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
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;
具体的这三个是什么效果,我还是建议大家试一下比较一下自己得出结论。
“mysql中的join、left join和right join的用法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!