Today, when I was looking at the laboratory projects, I encountered a "tricky" problem for me. In fact, it was because I was too stupid. Throw out the sql statement first // This statement cannot get the correct query result when id is not 1. select min(id+1) from oslist c where not exists (select id from oslist where id = c.id+1); When I first saw this query statement, I was completely confused, probably because I hadn’t touched SQL for a long time. 1 exists syntax In sql syntax, exists is used to filter results. During the actual execution process, the EXISTS statement loops the outer table and queries the inner table each time the loop is repeated. Substitute the records of the outer table into the subquery one by one. If the subquery result set is empty, it means it does not exist; otherwise, it exists. It should be noted here that substituting the records of the outer table into the subquery is only to see whether the query result is empty, rather than making a substantive value comparison. Let’s take an example: If the id in the table oslist is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15. The SQL statement at the beginning of the article is used here, using self-connection. Then the query process is as follows:
End the query. ps: Delete the data with the smallest id in MySQL //Method 1 delete from tablenamewhere id in (select id from (select min(id) id from tablenamec1) t1); //Method 2 delete from table name order by id asc limit 1; Summarize The above is the method that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: JavaScript uses promise to handle multiple repeated requests
>>: How to check the hard disk size and mount the hard disk in Linux
Vue uses Ref to get component instances across le...
Map tags must appear in pairs, i.e. <map> .....
Copy code The code is as follows: jQuery.cookie =...
I reinstalled the computer and installed the late...
Table of contents Overview Problem Description Ci...
We will use CSS3 animated transitions to create a...
1. There are two ways to modify global variables ...
Introduction to IPSec IPSec (Internet Protocol Se...
Note 1: Solve the problem of slow connection to M...
Log rotation is a very common function on Linux s...
Preface The count function is used to count the r...
Use pure CSS to change the background color of a ...
I'll record the problems I encountered during...
<body style="scroll:no"> <tabl...
When learning mybatis, I encountered an error, th...