Syntax alias problem based on delete in mysql

Syntax alias problem based on delete in mysql

MySQL delete syntax alias problem

First, confirm that the delete statement in MySQL supports aliases;

When writing the delete syntax yourself, the statement is as follows:

delete from tableA a where a.c_pk_id = '123'

However, an alias usage error will be reported, as follows:

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'q
WHERE
q.C_PLY_NO = '1100107000404000220150000001'
AND q.N_EDR_PRJ_NO = '1' at line 3

Through the query data, I learned that the syntax of MySQL delete is somewhat special, as follows:

delete a from tableA a where a.c_pk_id = '123'

Deleted successfully! ! !

After comparison, we can know that when using an alias in a delete statement, you need to write an additional alias after delete.

Using alias in mysql delete statement

grammar:

delete <alias> from <table> <alias> where <alias>.<field>...

The alias must appear once after the delete.

Deletion syntax between multiple tables:

DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND t2.id=t3.id;

Or:

DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND t2.id=t3.id;

LEFT JOIN:

DELETE t1 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL;

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Basic tutorial on using table aliases and field aliases in MySQL
  • MySQL data operation-use of DML statements
  • A comprehensive summary of frequently used statements in MySQL (must read)

<<:  Talking about ContentType(s) from image/x-png

>>:  Two methods to disable form controls in HTML: readonly and disabled

Recommend

CSS and HTML and front-end technology layer diagram

The relationship between Javascript and DOM is ve...

Docker nginx example method to deploy multiple projects

Prerequisites 1. Docker has been installed on the...

Mysql8.0 uses window functions to solve sorting problems

Introduction to MySQL Window Functions MySQL has ...

Complete steps to install mysql5.7 on Mac (with pictures and text)

I recently used a Mac system and was preparing to...

Markup language - web application CSS style

Click here to return to the 123WORDPRESS.COM HTML ...

How to load Flash in HTML (2 implementation methods)

First method : CSS code: Copy code The code is as ...

How to manage users and groups when running Docker

Docker is a management tool that uses processes a...

How to write a MySQL backup script

Preface: The importance of database backup is sel...

Example of using store in vue3 to record scroll position

Table of contents Overall Effect Listen for conta...

How to deploy Tencent Cloud Server from scratch

Since this is my first post, if there are any mis...

MySQL 5.7.18 winx64 installation and configuration method graphic tutorial

The installation of compressed packages has chang...

A brief discussion on the principle of Vue's two-way event binding v-model

Table of contents explain: Summarize Replenish Un...

Split and merge tables in HTML (colspan, rowspan)

The code demonstrates horizontal merging: <!DO...