声明:本文为本人在分析学习了其他网友的博文后,得出的一些体会。。编写本文的目的,一则,分享自己的学习体会,希望通过此文与其他正在学习数据库的网友互相交流,共同学习;二则,记录下学习中的点滴收获,供以后温习。本人为数据库初学者,有很多观点可
声明:本文为本人在分析学习了其他网友的博文后,得出的一些体会。。编写本文的目的,一则,分享自己的学习体会,希望通过此文与其他正在学习数据库的网友互相交流,共同学习;二则,记录下学习中的点滴收获,供以后温习。本人为数据库初学者,有很多观点可能存在错误,若诸位网友有不同观点,望不吝指教。
首先引用一下这位网友的博文,本人从此博文中受益良多,感谢此位网友的分享。
http://hi.baidu.com/woaidelphi/item/d96be15c3ce2c1cbd2e10c6c
author:华夏之星
QQ:1019822077
email:woai_php@sina.com
内连接: 只连接匹配的行
左外连接: 包含左边表的全部行(不管右边的表中是否存在与它们匹配的行),以及右边表中全部匹配的行
右外连接: 包含右边表的全部行(不管左边的表中是否存在与它们匹配的行),以及左边表中全部匹配的行
注:此博文中还讲述了其他连接方式,鉴于本人刚开始学习数据库,因此,仅研究较为普遍的3中方式。
内连接与左右连接
在网上看到很多讲述内连接和左右连接的博文,一直认为这是3类连接方式。但看完这篇博文后,认识到,其实这3中连接方式,实际可以分为
两类。一种内连接,一种外连接。而外连接又可分为左连接和右连接。
内连接的匹配方式
------------------------------------------------------------------------------再次引用-----------------------------------------------------------------------
举个例子吧。
表A
id name
1 张
2 李
3 王
表B
id address A_id
1 北京 1
2 上海 3
3 南京 10
/******************************** inner join 内连接*****************************************/
排他性:A,B表中至少有1个匹配时,才返回行。两表的交集
SQL语句如下:
select A.name,B.address from A
inner join B
on A.id = B.A_id
查询结果为:
name address
张 北京
王 上海
------------------------------------------------------------------------------引用结束-----------------------------------------------------------------------
此sql查询语句可按如下翻译:使用内连接的方式,选择出A中id与B中A_id相等的A表和B表中的行,然后将A表中行的name字段和B表中的address字段组合成行,作为查询结果。
具体过程可以描述为,对于A表中id为1的行(及表中第一行),与B表中的每一行都进行匹配,找到与B表中A_id字段相同的行(本例中B表的第一行便满足条件)。由于本例中,A表的第一行和B表的第一行便满足SQL语句的查询条件,因此,查询结果集的第一条结果为A表第一行的name(张)和B表第一行的address(北京)。然后,对A表的第二行进行匹配,遍历B表的所有行,没有找到满足与A表id(2)相同的A_id的行,因此。接着为A表的第3行,在B表中寻找匹配的行。遍历B表中所有的行,发现第二行的A_id(3)与A表id(3)匹配,因此,匹配成功,输出结果。自此,A表的所有行的查询了,本次SQL查询结束。结果有两条匹配的结果。
左右连接的匹配过程
--------------------------------------------------------------------------接着引用---------------------------------------------------------------
表A
id name
1 张
2 李
3 王
表B
id address A_id
1 北京 1
2 上海 3
3 南京 10
/********************************
left join 左连接*****************************************/
包容性:A表包容B表,左连接左表是全的.(left join 或 left outer join )
SQL语句如下:
SELECT A.name, B.address
FROM A
LEFT JOIN B ON A.id = B.A_id
查询结果为:
name address
张 北京
李 NULL
王 上海
/******************************** right join 右连接*****************************************/
包容性:B表包容A表,右连接右表是全的.(right join 或 right outer join )
SQL语句如下:
SELECT A.name, B.address
FROM A
RIGHT JOIN B ON A.id = B.A_id
查询结果为:
name address
张 北京
王 上海
NULL 南京
------------------------------------------------------------------------------引用结束-----------------------------------------------------------------------
左右连接的匹配过程与内连接的匹配过程相同,不同的是,左右连接查询时,SQL语句中,指定的基准表(right join 或left join 后的表)字段
无论是否在另一张表中有与之匹配的行,基准表中的字段均会输出。如上例左连接中的第二行,李(左连接基准表指定的查询字段)和右连接中的
第3行南京(右连接基准表中指定的查询字段)

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
