In mysql, you can use the count() function to determine whether data exists. The function of this function is to record data in the statistical table. The syntax is "select COUNT (field value) as field name from table name where Field condition;", the returned result is 0 and the data does not exist. If the result is greater than 0, it exists.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
Test to determine whether a record exists.
1. Open a query interface
2. The first method is to use the count function to obtain the number of records that meet the conditions according to the conditions. If it is equal to 0, it means it does not exist. If it is greater than 0, it means it exists.
The count() function is a function used to count records in the table and returns the number of rows matching the conditions.
Examples are as follows:
select COUNT(id) as amount from p_user where id=1;
Recommended learning: mysql video tutorial
The above is the detailed content of How to determine whether data exists in mysql. For more information, please follow other related articles on the PHP Chinese website!