The MySQL STRCMP() function compares two strings and returns 0 if equal, -1 if string1 is smaller, or 1 if string1 is larger. It allows developers to perform deterministic data transformations directly within SQL queries.
INTNULL if any required input argument evaluates to NULL.string1, string2-- Query demonstrating MySQL STRCMP() usage in production queries
SELECT STRCMP('apple', 'banana') AS cmp;
| cmp |
|---|
| -1 |
IFNULL() or COALESCE() if your input columns allow NULL values.WHERE clauses disables B-tree index lookups (causing full table scans). Use generated columns with indexes when querying heavily.Write a SQL query using STRCMP() to format or evaluate data retrieved from a database table.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With