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

28 Famous Blog Redesign Examples

1. WebDesignerWall 2. Veerle's Blog 3. Tutori...

Summary of several submission methods of HTML forms

The most common, most commonly used and most gener...

MySQL GROUP_CONCAT limitation solution

effect: The GROUP_CONCAT function can concatenate...

Monitor changes in MySQL table content and enable MySQL binlog

Preface binlog is a binary log file, which record...

CentOS 6.5 installation mysql5.7 tutorial

1. New Features MySQL 5.7 is an exciting mileston...

MySQL Router implements MySQL read-write separation

Table of contents 1. Introduction 2. Configure My...

On Visual Design and Interaction Design

<br />In the entire product design process, ...

MySQL NULL data conversion method (must read)

When using MySQL to query the database and execut...

Summary of the Differences between SQL and NoSQL

Main differences: 1. Type SQL databases are prima...

PHP related paths and modification methods in Ubuntu environment

PHP related paths in Ubuntu environment PHP path ...

Vue implements a simple shopping cart example

This article shares the specific code of Vue to i...

A brief discussion on spaces and blank lines in HTML code

All consecutive spaces or blank lines (newlines) ...

A Brief Analysis of MySQL - MVCC

Version Chain In InnoDB engine tables, there are ...

Analysis of CocosCreator's new resource management system

Table of contents 1. Resources and Construction 1...