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

Detailed explanation of MySQL index principles and optimization

Preface This article was written by a big shot fr...

Why does MySQL paging become slower and slower when using limit?

Table of contents 1. Test experiment 2. Performan...

SQL query for users who have placed orders for at least seven consecutive days

Create a table create table order(id varchar(10),...

CSS complete parallax scrolling effect

1. What is Parallax scrolling refers to the movem...

How to build nfs service in ubuntu16.04

Introduction to NFS NFS (Network File System) is ...

Key issues and solutions for web page access speed

<br /> The website access speed can directly...

Implementation of Jenkins+Docker continuous integration

Table of contents 1. Introduction to Jenkins 2. I...

HTML Nine-grid Layout Implementation Method

Diversifying website layouts is our front-end spe...

Usage and demonstration of ref in Vue

ref definition: used to register reference inform...

Centos7 installation of FFmpeg audio/video tool simple document

ffmpeg is a very powerful audio and video process...

Summary of 16 XHTML1.0 and HTML Compatibility Guidelines

1. Avoid declaring the page as XML type . The pag...

How to check the version of Kali Linux system

1. Check the kali linux system version Command: c...

How to use CURRENT_TIMESTAMP in MySQL

Table of contents Use of CURRENT_TIMESTAMP timest...