当前位置:网站首页>Mysql database knowledge points (III)
Mysql database knowledge points (III)
2022-06-22 19:53:00 【zhulin1028】
Keep creating , Accelerate growth ! This is my participation 「 Nuggets day new plan · 6 Yuegengwen challenge 」 Of the 25 God , Click to see the event details
One 、 The joint query
UNION The operator can add two or more to SELECT The query result set of the statement is combined into a result set to display , That is, the union query is executed .UNION The grammar format of is :
select_statement UNION [ALL] selectstatement
[UNION [ALL] selectstatement][…n] among selectstatement For... To be united SELECT Query statement .
ALL Option means to merge all rows into the result set . When this item is not specified , Only one row is reserved for duplicate rows in the federated query result set .
Joint query , The column title of the query result is the column title of the first query statement . therefore , To define column headings, you must define... In the first query statement . When sorting union query results , You must also use the column names in the first query statement 、 Column header or column sequence number .
In the use of UNION Operator , Ensure that there are the same number of expressions in the selection list of each joint query statement , And each query selection expression should have the same data type , Or they can be automatically converted to the same data type . During automatic conversion , For numeric types , The system converts low-precision data types into high-precision data types .
Where multiple queries are included UNION In the sentence , The execution sequence is from left to right , Use parentheses to change this execution order . for example : Inquire about 1 UNION ( Inquire about 2 UNION Inquire about 3)
Two 、 Link query
Multiple table queries can be implemented through join operators . Connection is the main feature of relational database model , It is also a symbol that distinguishes it from other types of database management systems .
In relational database management system , When creating a table, the relationship between the data does not have to be determined , All the information of an entity is often stored in one table . When retrieving data , Query the information of different entities stored in multiple tables through connection operation . Connection operation brings great flexibility to users , They can add new data types at any time . Create new tables for different entities , Then query by connection .
You can connect at SELECT Of the statement FROM Clause or WHERE Clause , Specious in FROM Clause helps to link the join operation to WHERE The search conditions in the clause are distinguished . therefore , stay Transact-SQL This method is recommended in .SQL-92 The standard defines FROM The join syntax format of clause is :
FROM join_table join_type join_table [ON (join_condition)]
among join_table Indicates the name of the table participating in the join operation , Join can operate on the same table , You can also operate on multiple tables , A join to the same table operation is also called a self join .join_type Point out the connection type , It can be divided into three kinds : Internal connection 、 External connections and cross connections .
Internal connection (INNER JOIN) Use the comparison operator to perform a comparison between tables ( some ) Comparison of column data , And list the data rows in these tables that match the connection conditions . Depending on the comparison method used , Internal connection is divided into equivalent connection 、 Natural connection and unequal connection .
External connection is divided into left external connection (LEFT OUTER JOIN or LEFT JOIN)、 Right connection (RIGHT OUTER JOIN or RIGHT JOIN) And all outside connection (FULL OUTER JOIN or FULL JOIN) Three . Unlike the inner connection , The external connection lists not only the rows that match the connection conditions , Instead, list the left table ( Left outer connection )、 Right table ( Right outer connection ) Or two tables ( When fully externally connected ) All data rows that meet the search criteria in the .
Cross connect (CROSS JOIN) No, WHERE Clause , It returns the Cartesian product of all data rows in the join table , The number of data rows in the result set is equal to the number of qualified data rows in the first table multiplied by the number of qualified data rows in the second table .
In connection operation ON (join_condition) Clause indicates the join condition , It consists of columns in the connected table and comparison operators 、 Logical operators, etc . No connection can be made to text、ntext and image Data type column for direct connection , But you can connect these three columns indirectly . for example :
SELECT p1.pub_id,p2.pub_id,p1.pr_info FROM pub_info AS p1 INNER JOIN pub_info AS p2
ON DATALENGTH(p1.pr_info)=DATALENGTH(p2.pr_info)
边栏推荐
猜你喜欢

详解openGauss多线程架构启动过程

故障分析 | 从 data_free 异常说起

Yarn notes

知识蒸馏之Focal and Global Knowledge Distillation for Detectors

1.4----- PCB design? (circuit design) determination scheme

1.2----- mechanical design tools (CAD software) and hardware design tools (EDA software) and comparison

图的定义及术语

Compilation error: /usr/bin/ld: /usr/local/lib/libgflags a(gflags.cc.o): relocation R_ X86_ 64_ 32S against `. rodata‘

84. (cesium chapter) movement of cesium model on terrain

Modify the antd tree component so that its subclasses are arranged horizontally.
随机推荐
树和森林的遍历
ABAQUS 使用RSG绘制插件初体验
优化了一半的SQL
1.4----- PCB design? (circuit design) determination scheme
C WinForm embedded flash
[nfs无法挂载问题] mount.nfs: access denied by server while mounting localhost:/data/dev/mysql
0.0 - how can SolidWorks be uninstalled cleanly?
Mini web framework: template replacement and routing list function development | dark horse programmer
2. what is mechanical design?
佐治亚理工学院|具有服务质量保证的多无人机野火协同覆盖和跟踪规划
如何在 FlowUs和Notion 等笔记软件中进行任务管理?
0.1----- process of drawing PCB with AD
Redis 大 key 问题
Damp 3D printer consumables
Focal and global knowledge distillation for detectors
1.2----- mechanical design tools (CAD software) and hardware design tools (EDA software) and comparison
MySQL约束
编译报错:/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata‘
Decorator mode of structural mode
c# winform 嵌入flash