The SQL statement is as follows:
Select * from LOAN_BACK_LIBRARY where LIBRARY_ID = 1 or LIB_ID = 1 and STATUS = 3
The conditions for my desired results are:1. LIBRARY_ID = 1 or LIB_ID = 1
2. STATUS = 3
But this is not the case. STATUS is displayed! But it matches LIBRARY_ID = 1 or LIB_ID = 1.
Why?
The original execution of this SQL statement is as follows:
Select * from LOAN_BACK_LIBRARY whereLIBRARY_ID = 1OrLIB_ID = 1 and STATUS = 3
To:
Select * from LOAN_BACK_LIBRARY whereSTATUS = 3 and LIBRARY_ID = 1OrLIB_ID = 1 Still incorrect
Haha, I found the problem:
If the where clause has the and or clause, the or clause automatically separates the Left and Right query conditions, that is, the and clause is executed first, and then the or clause is executed. The reason is: and has the highest execution priority!
Relational operators with a high priority: not and or
The solution is:
Use () to change the execution sequence !!!!
The preceding SQL statement is as follows:
Select * from LOAN_BACK_LIBRARY whereSTATUS = 3 and (LIBRARY_ID = 1OrLIB_ID = 1)
This is the perfect answer !!!!