Multi-table join queryThe connection between tables is divided into inner connection and outer connection
Inner Join First, prepare two tables Student table Score table Inner join: Find the common records that meet the conditions in each table. Query the student names and scores in the student table. The first way to write: only use where select a.s_name, b.s_score from student a,score b where a.s_id = b.s_id; The second way to write it: join ... on ... select a.s_name, b.s_score from student a join score b on a.s_id = b.s_id The third way to write it: inner join … on… select a.s_name, b.s_score from student a inner join score b on a.s_id = b.s_id Left JoinLeft join: According to the records in the left table, find the records that meet the conditions in the connected right table to match them. If no records matching the left table are found, null is used to represent them. The first way to write it: left join … on … select a.s_name,b.s_score from student a left join score b on a.s_id = b.s_id The second way of writing: left outer join … on … select a.s_name,b.s_score from student a left outer join score b on a.s_id = b.s_id Right Join**Right join: **According to the records in the right table, find the records that meet the conditions in the connected left table to match them. If no match is found, it is represented by null. The first way to write it: right join … on … select a.s_name,b.s_score from student a right join score b on a.s_id = b.s_id; The second way of writing: right outer join … on … select a.s_name,b.s_score from student a right outer join score b on a.s_id = b.s_id; SubqueriesSubquery : It is a way to implement multi-table join query. Another select statement is nested in the from clause or where clause of a select statement. The outer select query statement becomes the main query. In other words , the query statement in WHERE or FORM is called a subquery. Subquery in WHERE clause: The value returned by the subquery is used as the query condition of the main query Subquery in the FROM clause: The subquery returns a virtual table, and the main query finds the conditions that meet the conditions from the temporary table. SummarizeThis article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Linux operation and maintenance basics httpd static web page tutorial
>>: How to use CSS3 to implement a queue animation similar to online live broadcast
First look at the effect: Preface: I came up with...
This article example shares the specific code of ...
Definition of Generics // Requirement 1: Generics...
1. Install zabbix-agent on web01 Deploy zabbix wa...
Preface Because the mini program upload requires ...
Query the MySQL source first docker search mysql ...
A set of projects for training react+ts Although ...
Use the for loop to import the zabbix image into ...
Table of contents Preface Lua Script nignx.conf c...
I found a strange problem when deploying the proj...
Body part: <button>Turn on/off light</bu...
In the world of web development, frameworks are ve...
In general guestbooks, forums and other places, t...
Table of contents 1. What is a calculated propert...
Installation environment: CAT /etc/os-release Vie...