mysql three tables connected to create a view

mysql three tables connected to create a view

Three tables are connected. Field a of table A corresponds to field b of table B, and field b1 of table B corresponds to field c of table C.

Now create a view to see all the information of the three tables at the same time.

create or replace view v_name
as
select t1.*,t2.*,t3.*
from table A t1, table B t2, table C t3
where t1.a=t2.b and t2.b1=t3.c

Create a view by linking two tables

CREATE TABLE `aa_user` (
 `id` int(10) NOT NULL,
 `name` varchar(10) DEFAULT NULL,
 `age` int(10) DEFAULT NULL,
 PRIMARY KEY (`id`)

)ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `aa_user` VALUES ('1', 'zs', '18');
INSERT INTO `aa_user` VALUES ('2', 'ls', '20');
INSERT INTO `aa_user` VALUES ('3', 'ww', '19');

CREATE TABLE `tb` (
 `id` int(10) NOT NULL,
 `fid` int(10) DEFAULT NULL,
 `cc` int(10) DEFAULT NULL,
 PRIMARY KEY (`id`)

)ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `tb` VALUES ('1', '1', '60');
INSERT INTO `tb` VALUES ('2', '1', '70');
INSERT INTO `tb` VALUES ('3', '2', '80');

INSERT INTO `tb` VALUES ('4', '2', '90');

Creating a View

CREATE or REPLACE view aa_ta_view AS
select a.*,b.fid,b.cc from aa_user a,tb b 
where a.id = b.fid;

You may also be interested in:
  • Comparison of efficiency between single-table query and multi-table join query in MySql database
  • Detailed explanation of MySQL multi-table join query
  • A brief discussion on the execution details of Mysql multi-table join query
  • MySQL multi-table join introductory tutorial
  • MySQL multi-table join query example explanation
  • A simple tutorial on optimizing table join queries in MySQL
  • Basic multi-table join query tutorial in MySQL
  • MySQL and PHP basics and application topics: table connection

<<:  Solve the problem of "Welcome to nginx on Fedora!" after installing nginx on Centos7, and there is no default.conf file in the conf.d directory

>>:  How to use Vue to develop public account web pages

Recommend

In-depth understanding of the use of Vue

Table of contents Understand the core concept of ...

This article will show you how to use SQL CASE WHEN in detail

Table of contents Simple CASEWHEN function: This ...

MySQL 5.7.23 decompression version installation tutorial with pictures and text

Download the MySQL installer Official download ad...

Summary of Vue3 combined with TypeScript project development practice

Table of contents Overview 1. Compositon API 1. W...

VMware Workstation 14 Pro installation Ubuntu 16.04 tutorial

This article records the specific method of insta...

In-depth explanation of hidden fields, a new feature of MySQL 8.0

Preface MySQL version 8.0.23 adds a new feature: ...

How to use geoip to restrict regions in nginx

This blog is a work note environment: nginx versi...

Native js to implement a simple calculator

This article example shares the specific code of ...

Detailed explanation of the difference between alt and title

These two attributes are often used, but their di...

Vue.js $refs usage case explanation

Despite props and events, sometimes you still nee...

9 Tips for MySQL Database Optimization

Table of contents 1. Choose the most appropriate ...

Basic reference types of JavaScript advanced programming

Table of contents 1. Date 2. RegExp 3. Original p...

How to use docker to deploy Django technology stack project

With the popularity and maturity of Docker, it ha...

Basic knowledge of HTML: a preliminary understanding of web pages

HTML is the abbreviation of Hypertext Markup Langu...

A link refresh page and js refresh page usage examples

1. How to use the link: Copy code The code is as f...