I have a SQL query SELECT * FROM table WHERE column LIKE '%pdd%'
.
The problem is I need to get all results excluding those which start with "pdd", by which I mean find everything where "pdd" is not at the beginning. How could it be done?
I do need to match "pdd" when it is not at the beginning of the column.
SUBSTRING() function in MySQL function in MySQL is used to derive substring from any given string . It extracts a string with a specified length, starting from a given location in an input string. The purpose of substring is to return a specific portion of the string.
MySQL query string contains using LOCATE We will be using the LOCATE() function for the solution. LOCATE(substr, str) function returns the first occurrence of the substring passed in as parameters. Here substr is the substring passed in as the first argument, and str is the string passed in as the second argument.
INSTR() function MySQL INSTR() takes a string and a substring of it as arguments, and returns an integer which indicates the position of the first occurrence of the substring within the string.
CHARINDEX function in SQL queries The CHARINDEX() function returns the substring position inside the specified string. It works reverse to the SUBSTRING function. The substring() returns the string from the starting position however the CHARINDEX returns the substring position.
I assume you mean all rows that match "pdd" except those where "pdd" is at the beginning.
SELECT * FROM table WHERE column LIKE '_%pdd%'.
The "_
" wildcard in LIKE
predicates means "one of any character," equivalent to ".
" in regular expressions.
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