Can I use wildcards in IN MySQL statement?
I'm not sure it's any better than what you came up with but you could use MySQL's regex capabilities:
select * from my_table where field rlike 'apple|orange';
Also, as others have mentioned, you could use MySQL's full text search capabilities (but only if you're using the MyISAM engine).
mysql cant add wildcard in IN Operator
Your query doesn't work because your '%' is being interpreted as the modulo operator which is a binary operator and as such makes your syntax invalid.
SELECT * FROM `cdr` WHERE `src` like '5%' OR src LIKE '9725%' OR src LIKE '05%';
If you want to use the '%' character as a wild card it has to be quoted and used with the LIKE operator.
Types of Wildcards in MySql
Thanks everyone!
For specific this question, we need to use regexp
Select * From tableName Where ColumnName Regexp "^[PST]";
For more detail over Regular Expression i.e Regexp :
https://www.youtube.com/watch?v=KoltE-JUY0c
Using wildcards with the MYSQL IN Clause
Not really. You are better off with regular expressions. Something like this:
where customerid regexp 'apple|pear|banana'
This will return customer ids that have 'apple' or 'pear' or 'banana' anywhere.
If you really wanted to use like
you need multiple comparisons:
where customerid like '%apple%' or
customerid like '%pear%' or
customerid like '%banana%'
MySQL Wildcards * and %
*
can only be used as a wildcard (or truncation) in a full text search while %
(match 0 or more characters) and _
(match exactly one character) are only applicable in LIKE-queries.
SQL In() with Wildcard Operators For MULTIPLE COLUMNS
You could just concatinate them with a separator.
SELECT *
FROM your_table
WHERE CONCAT_WS('|', col1, col2, col3, col4) LIKE '%text%'
In MySql 8 one could also use an EXISTS
for this
SELECT *
FROM your_table t
WHERE EXISTS (
select 1
from (
select t.col1 as col union all
select t.col2 union all
select t.col3 union all
select t.col4
) q
where col LIKE '%text%'
);
Demo on db<>fiddle here
How to use LIKE and wildcards in mysql statements
You could use MySQL function FIND_IN_SET:
SELECT * FROM tbl
WHERE
FIND_IN_SET('16', REPLACE(kategorien, ';', ','))>0
however, it is usually not a good idea to store comma separated values in a single field, please have a look at this question: Is storing a delimited list in a database column really that bad?
SQL - How to use wildcard in LIKE as a normal character
try this :
select * from TABLE where VALUES like '%[%]%'
Related Topics
Update X Set Y = Null Takes a Long Time
Simple Db2 Query for Connection Validation
Sql Server 2012: Add a Linked Server to Postgresql
Varchar(Max) Ms SQL Server 2000, Problems
Handling Null in Greatest Function in Oracle
Crosstab Query with Dynamic Columns in SQL Server 2005 Up
Null Value for Int in Update Statement
Automatically Create Scripts for All SQL Server Jobs
How to Use Many Like Operators and Use Index
Sql: Insert Into...Values..Select
Unique Date Range Fields in SQL Server 2008
Delete ... from ... Where ... In
Merge Two Tables/Concatenate Values into Single Column
Postgresql - Conditional Ordering
Are Brackets in The Where Clause Standard Sql