I am glad if any one could help me out here.
I have a table Table1 and column XXXXXX with the data as following
XXXXXX
---------
1
2
1
2
x_y
A_12
3
12345_abcd
I want the output as
XXXXXX
---------
1
2
3
I have tried the following query
select DISTINCT XXXXXX from Table1 where XXXXXX NOT LIKE '%_%';
Also tried SELECT DISTINCT XXXXXX FROM Table1 WHERE CHAR ('_','XXXXXX')=0;
The above query is fetching everything from the table. Can anyone help me on this issue.
Try:
The “escape” character is what tells MySQL that the underscore is to be interpreted as literal underscore character, and not a wildcard. (In the LIKE expression, an underscore (
_) is a wildcard that matches any single character, just as the percent (%) is a wildcard that matches zero, one or more characters.Note that other characters can be used as the escape character; it doesn’t have to be the backslash. The backslash is itself an escape character in MySQL, so have a backslash recognized as the escape character for the LIKE, we have to use double backslashes “
\\“. That makes MySQL recognize this as a single backslash character.As an example, we can use the carat “
^” character as the escape character, like this:Similarly, the escape character can be used to search for a literal percent sign
%using a LIKE operator like this:(That will search for an occurrence of a percent sign character in foo.)
As an alternative to the NOT LIKE operator, we can use the ‘NOT REGEXP’ operator to exclude rows where foo contains an underscore character, like this: