I want to select titles that have a number after a certain character. Example:
SELECT * FROM table WHERE title LIKE '%- H(any number)'
How would I select any number in this statement 1-10000000 if the number exists?
MySQL Wildcards A wildcard character is used to substitute one or more characters in a string. Wildcard characters are used with the LIKE operator. The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
MySQL uses C escape syntax in strings (for example, \n to represent the newline character). If you want your expr or pat argument to contain a literal \ , you must double it.
SQL pattern matching enables you to use _ to match any single character and % to match an arbitrary number of characters (including zero characters). In MySQL, SQL patterns are case-insensitive by default.
It is in PostgreSQL the keyword ILIKE can be used instead of LIKE to make the match case-insensitive according to the active locale. This is not in the SQL standard but is a PostgreSQL extension. In MySQL you do not have ILIKE.
SELECT * FROM table WHERE title REGEXP '.*- H[0-9]+'
That seems like the kind of thing you're looking for.
SELECT * FROM table WHERE title RLIKE '- H[:digit:]{1,7}$';
will give you 1-9999999
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With