A brief discussion on using Cartesian product principle to query multiple tables in MySQL

A brief discussion on using Cartesian product principle to query multiple tables in MySQL

MySQL multi-table query (Cartesian product principle)

  1. First determine which tables the data will use.
  2. Convert multiple tables into one table through Cartesian product.
  3. Then remove the illogical data (remove it according to the relationship between the two tables).
  4. Finally, just add conditions as if it were a virtual table.

Note: It is best to use table aliases to distinguish column names.

Cartesian Product

Demo:

Left, right, inner, outer joins

Inner join:

Important: All matching records are returned.

select * from a,b where ax = bx ////Inner join

l There are two types of outer joins: left join and right join.

Key points: All matching records are returned plus one record for each row where the primary table foreign key value is null. All columns of the auxiliary table are null values.

select * from a left join b on ax=bx order by ax //Left outer join or left join select * from a right join b on ax=bx order by ax //Right outer join or right join

Select clause order

Clauses illustrate Is it necessary to use
select The column or expression to return yes
form The table from which to retrieve data Only used when selecting data from a table
where Row-level filtering no
group by Group Description Only used when computing aggregates by group
having Group level filtering no
order by Output sort order no
limit The number of rows to retrieve no

This concludes this article on how to use the Cartesian product principle in MySQL to perform multi-table queries. For more information about MySQL multi-table queries, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySql multi-table query transaction and DCL
  • Detailed explanation of four types of MySQL connections and multi-table queries
  • Specific example of MySQL multi-table query
  • MySQL database advanced query and multi-table query
  • MySQL multi-table query detailed explanation
  • MySQL multi-table query detailed explanation
  • MySQL left-join multi-table query where condition writing example
  • Analyzing the implementation of Mysql multi-table query
  • MySQL multi-table query implementation analysis
  • Detailed classification of MySQL multi-table queries

<<:  Detailed explanation of Linux rpm and yum commands and usage

>>:  Detailed tutorial on installing MariaDB on CentOS 8

Recommend

How to build a MySQL PXC cluster

Table of contents 1. Introduction to PXC 1.1 Intr...

Alibaba Cloud Server Ubuntu Configuration Tutorial

Since Alibaba Cloud's import of custom Ubuntu...

Detailed explanation of the principle and usage of MySQL stored procedures

This article uses examples to explain the princip...

Detailed explanation of MySQL master-slave database construction method

This article describes how to build a MySQL maste...

How to use the jquery editor plugin tinyMCE

Modify the simplified file size and download the ...

MySQL efficient query left join and group by (plus index)

mysql efficient query MySQL sacrifices group by t...

Get / delete method to pass array parameters in Vue

When the front-end and back-end interact, sometim...

Summary of Linux command methods to view used commands

There are many commands used in the system, so ho...

Tomcat class loader implementation method and example code

Tomcat defines multiple ClassLoaders internally s...

Vue el-date-picker dynamic limit time range case detailed explanation

There are two situations 1. Start time and end ti...

Analysis of slow insert cases caused by large transactions in MySQL

【question】 The INSERT statement is one of the mos...