Search query from multiple fields SQL LIKE Clause In MySQL - mysql

When I run this query it's not working
SELECT * FROM `tbl_skill` WHERE `skill_name` LIKE '%PHP%Asp%'

Try using RLIKE, example:
SELECT * FROM tbl_skill WHERE skill_name RLIKE 'PHP|Asp';

You cannot use the LIKE operator like an or operator.
for each LIKE term you need to have an additional OR for other searches.
SELECT * FROM tbl_skill WHERE skill_name LIKE '%PHP%' OR skill_name LIKE '%Asp%'
If you don't want an array...
SELECT * FROM tbl_skill WHERE skill_name LIKE ANY(ARRAY['%PHP%','%Asp%'])

Related

MySQL combining two where operators WHERE row LIKE '%$search%' AND WHERE NOT row='$id'

SELECT * FROM table_name WHERE column_name LIKE '%$search%' AND WHERE NOT column_name='$id';
I want to select all the results from my database that are like my search term, but exclude the row that is equal to my php variable $id.
Is it possible to do this in a MySQL query?
Put the all the conditions inside a single WHERE block and use conditional operators like AND/OR/NOT to combine them
SELECT * FROM table
WHERE `row` LIKE '%$search%' AND
`row` <> '$id';
Also, please learn to use Prepared Statements

Mysql - how to use like on multiple columns

I've searched in mysql query a word in multiple column in java program. The number of column is variable.
It is correct this query:
select * from customer with (city, name) like%'adelaide'%
You can use CONCAT() function:
select * from customer WHERE concat(city,name) like '%adelaide%'
You can add as many columns to the concat function as you like.
Also as you see I changed your like syntax, '%WORD%' and used a simple where clause.
It's better to use CONCAT_WS() function.
CONCAT() returns NULL if any argument is NULL.
CONCAT_WS() skip any NULL values after the separator argument.
multiple like statements can not be used with or directly. You have to use column name for each like statement.
Use multiple like as mentioned below.
Select *
from animals
where
(
[animalscolumn] like ('%dog%') or
[animalscolumn] like ('%cat%') or
[animalscolumn] like ('%gerbil%') or
[animalscolumn] like ('%hamster%') or
[animalscolumn] like ('%guinea pig%')
)
select * from customer with city like%'adelaide'% or name like%'adelaide'%

how do i write a sql query to select the names that may contain any one of the vowels?

I m trying to query a database with about 2000 entries. I want to select the entries in which the names may contain any one of the vowel.
I tried using the following query, but it gives me those entries that contain all the given characters in that order.
select * from myTable where name like '%a%e%i%';
How do I modify the above query to select those entries with names that may contain at least anyone of the vowels.
Try this for SQL Server:
SELECT * FROM myTable WHERE name LIKE '%[AEIOU]%';
I hope this helps you...
SELECT * FROM myTable WHERE name REGEXP 'a|e';
or.....
SELECT * FROM myTable WHERE name REGEXP 'a|e|i';
In SQL Server, you would do:
where name like '%[aeiou]%';
In MySQL, you would do something similar with a regular expression.
Use OR like this.
This will work for both SQL Server and MySql.
select * from myTable where name like '%a%' OR name like '%e%' OR name like '%i%';
Use LIKE and OR.
Query
select * from myTable
where name like '%a%'
or name like '%e%'
or name like '%i%'
or name like '%o%'
or name like '%u%'

how to restrict `like` operator in query to start with something

I want to write a query that title start with A or B
is this correct?
I dont want use OR
I want use it in mysql ,
select * from table where title like `[AB]%`
Use REGEXP instead of LIKE:
SELECT * FROM table
WHERE title REGEXP '^[AB]'
DEMO
Or just use a substring:
SELECT * FROM table
WHERE LEFT(title, 1) IN ('A', 'B');
you can do it like
select * from table where title like `A%` OR title like `B%`
another way is to use regular expression
select * from table where title REGEXP '^(A|B)';
This is correct way:
SELECT * FROM table WHERE title LIKE 'A%' or title LIKE 'B%';
What you wrote should work. or you can use,
select *
from table_name
where title LIKE 'A%' OR title LIKE 'B%'
Unfortunately, the LIKE operator in SQL only supports a limited syntax. It doesn't support a regex style syntax.
You have to do divide it into two expressions:
select * from table where (title like 'A%' or title like 'B%')
Note:
In this case the parenthesis are superfluous, but since OR has a lower precedence than AND I think it is good practice to routinely add parenthesis around ORexpressions in SQL.

mySQL LIKE operator that does not equal

How can i write a mySQL query where i am looking for something using the LIKE operator and NOT equaling what is LIKE?
select * from ets_fi where name like '%barcode&' <> '%barcode%';
NOT LIKE
select * from ets_fi where name NOT LIKE '%barcode%';
OR, if I misunderstood your intention, you may want:
select * from ets_fi where name LIKE '%barcode%' AND name != 'barcode';