Please help me to write a sql query with the conditions as 'NOT LIKE IN'
请帮我写一个条件为'NOT LIKE IN'的SQL查询
Select * from Table1 where EmpPU NOT Like IN ('%CSE%', '%ECE%', '%EEE%')
Getting error.
得到错误。
6 个解决方案
#1
59
You cannot combine like and in. The statement below would do the job though:
你不能把喜欢和结合起来。下面的声明可以完成这项工作:
Select * from Table1
where EmpPU NOT Like '%CSE%'
AND EmpPU NOT Like '%ECE%'
AND EmpPU NOT Like '%EEE%'
#2
14
That's because you're mixing two syntax together.
那是因为你将两种语法混合在一起。
If you always have exactly those three values, you can just AND the results of three LIKE expressions.
如果你总是拥有这三个值,你可以只得到三个LIKE表达式的结果。
SELECT
*
FROM
Table1
WHERE
EmpPU NOT LIKE '%CSE%'
AND EmpPU NOT LIKE '%ECE%'
AND EmpPU NOT LIKE '%EEE%'
If you need to do it for "any number" of values, you can put the values into a table and do a join.
如果需要对“任意数量”的值执行此操作,可以将值放入表中并进行连接。
WITH
myData
AS
(
SELECT '%CSE%' AS match
UNION ALL SELECT '%ECE%' AS match
UNION ALL SELECT '%EEE%' AS match
)
SELECT
*
FROM
Table1
LEFT JOIN
myData
ON Table1.EmpPU LIKE myData.match
WHERE
myData.match IS NULL
OR...
要么...
WITH
myData
AS
(
SELECT '%CSE%' AS match
UNION ALL SELECT '%ECE%' AS match
UNION ALL SELECT '%EEE%' AS match
)
SELECT
*
FROM
Table1
WHERE
NOT EXISTS (SELECT * FROM myData WHERE Table1.EmpPU LIKE match)
#3
7
If you have set of words which you want to include/exclude in search from a particular column. You may want to use regular expression function of mysql.
如果您要在特定列的搜索中包含/排除单词集。您可能希望使用mysql的正则表达式函数。
Exclude set of words from a column :
从列中排除一组单词:
SELECT
*
FROM
Table1
WHERE
EmpPU NOT REGEXP 'CSE|ECE|EEE';
Search set of words from a column :
从列中搜索单词集:
SELECT
*
FROM
Table1
WHERE
EmpPU REGEXP 'CSE|ECE|EEE';
#4
3
you cant combine LIKE and IN
你不能把LIKE和IN结合起来
you can do:
你可以做:
select * from Table1
where EmpPU not in ('%CSE%', '%ECE%', '%EEE%')
but you wont benefit from the % wildcard
但你不会受益于%通配符
if you need the % the only option is:
如果您需要%,唯一的选择是:
Select * from Table1
where EmpPU not like '%CSE%' and EmpPU not like '%ECE%' and EmpPU not like '%EEE%'
#5
1
Or you can do it like this:
或者你可以这样做:
SELECT
*
FROM
Table1
WHERE NOT EXISTS
(
SELECT
NULL
FROM
(
SELECT '%CSE%' AS column1 UNION ALL
SELECT '%ECE%' UNION ALL
SELECT '%EEE%'
) AS tbl
WHERE Table1.EmpPU LIKE tbl.column1
)
#6
0
you can try this
你可以试试这个
Select * from Table1 where
EmpPU NOT Like '%CSE%'
AND EmpPU NOT Like '%ECE%'
AND EmpPU NOT Like '%EEE%'
#1
59
You cannot combine like and in. The statement below would do the job though:
你不能把喜欢和结合起来。下面的声明可以完成这项工作:
Select * from Table1
where EmpPU NOT Like '%CSE%'
AND EmpPU NOT Like '%ECE%'
AND EmpPU NOT Like '%EEE%'
#2
14
That's because you're mixing two syntax together.
那是因为你将两种语法混合在一起。
If you always have exactly those three values, you can just AND the results of three LIKE expressions.
如果你总是拥有这三个值,你可以只得到三个LIKE表达式的结果。
SELECT
*
FROM
Table1
WHERE
EmpPU NOT LIKE '%CSE%'
AND EmpPU NOT LIKE '%ECE%'
AND EmpPU NOT LIKE '%EEE%'
If you need to do it for "any number" of values, you can put the values into a table and do a join.
如果需要对“任意数量”的值执行此操作,可以将值放入表中并进行连接。
WITH
myData
AS
(
SELECT '%CSE%' AS match
UNION ALL SELECT '%ECE%' AS match
UNION ALL SELECT '%EEE%' AS match
)
SELECT
*
FROM
Table1
LEFT JOIN
myData
ON Table1.EmpPU LIKE myData.match
WHERE
myData.match IS NULL
OR...
要么...
WITH
myData
AS
(
SELECT '%CSE%' AS match
UNION ALL SELECT '%ECE%' AS match
UNION ALL SELECT '%EEE%' AS match
)
SELECT
*
FROM
Table1
WHERE
NOT EXISTS (SELECT * FROM myData WHERE Table1.EmpPU LIKE match)
#3
7
If you have set of words which you want to include/exclude in search from a particular column. You may want to use regular expression function of mysql.
如果您要在特定列的搜索中包含/排除单词集。您可能希望使用mysql的正则表达式函数。
Exclude set of words from a column :
从列中排除一组单词:
SELECT
*
FROM
Table1
WHERE
EmpPU NOT REGEXP 'CSE|ECE|EEE';
Search set of words from a column :
从列中搜索单词集:
SELECT
*
FROM
Table1
WHERE
EmpPU REGEXP 'CSE|ECE|EEE';
#4
3
you cant combine LIKE and IN
你不能把LIKE和IN结合起来
you can do:
你可以做:
select * from Table1
where EmpPU not in ('%CSE%', '%ECE%', '%EEE%')
but you wont benefit from the % wildcard
但你不会受益于%通配符
if you need the % the only option is:
如果您需要%,唯一的选择是:
Select * from Table1
where EmpPU not like '%CSE%' and EmpPU not like '%ECE%' and EmpPU not like '%EEE%'
#5
1
Or you can do it like this:
或者你可以这样做:
SELECT
*
FROM
Table1
WHERE NOT EXISTS
(
SELECT
NULL
FROM
(
SELECT '%CSE%' AS column1 UNION ALL
SELECT '%ECE%' UNION ALL
SELECT '%EEE%'
) AS tbl
WHERE Table1.EmpPU LIKE tbl.column1
)
#6
0
you can try this
你可以试试这个
Select * from Table1 where
EmpPU NOT Like '%CSE%'
AND EmpPU NOT Like '%ECE%'
AND EmpPU NOT Like '%EEE%'