I want to use LIKE query to select some specific word just like UU1.
I use
SELECT UniID FROM MasterCustomer where (UniID like '%uu1%' )
But it also returns a row which contains UU11.
How can I modify my query to select only UU1?
My table contains values like
UU1-UU7-UU5
UU2-UU1
UU3-UU1
UU31-UU14
try this:
SELECT UniID
FROM MasterCustomer
WHERE (UniID like '%uu1' ) OR (UniID like '%uu1-%' )
like '%uu1-%' or like '%uu1 %'
Another alternative:
WHERE UnitID + '-' LIKE '%uu1-%'
Related
I have to display the names of jobs which contains letters m or p . does'nt matter the position of letters where they are at .they can be either at starting or middle or what ever position.
thank you
Hi you can use like query for this type result-
SELECT column_name FROM table_name WHERE job like ('%m%') OR job like ('%p%');
Try this one:
select name,job from employee where jobtitle like '%M%' or '%P%'
As an alternative to LIKE, we can use REGEXP here:
SELECT job
FROM jobs
WHERE job REGEXP 'm|p';
Demo
TRY This one
SELECT * FROM `TABLENAME` WHERE 'JOBNAME' LIKE '%p%' OR 'JOBNAME' LIKE '%m%'
How can I use SQL like to only display single words that are in a particular column of any row? For example, suppose I have the following rows in column1.
Column1
put return
need return
got return
bring return
server
client
The single-words output I would like is:
server
client
Can this be accomplish using like? I know this can be accomplished using regular expressions, but if possible, I would prefer using LIKE.
You can use not like:
where col not like '% %'
SELECT * FROM YourTable
WHERE Column1 NOT LIKE '% %'
Or:
WHERE LOCATE(' ',Column1) = 0
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%'
I have a table in which one column is filled with data like 32;3;13;33;43
so
SELECT * FROM table;
gives something like
name ids
vegetables 13;3;63
fruits 37;73;333
When I'm querying MySQL like
SELECT * FROM table WHERE ids LIKE '%3%'
it gives me both records but obviously I want only this containing 3.
How to query MySQL correctly?
Try to use:
SELECT * FROM table WHERE CONCAT(';',ids,';') LIKE '%;3;%'
You will need to cover the case where it's the first in the list and the last.
SELECT * FROM table WHERE ids LIKE '%;3;%' OR LIKE '%;3' OR LIKE '3;%'
You can use FIND_IN_SET, if you replace the ; with a , before checking the value:0
SELECT *
FROM table
WHERE FIND_IN_SET('3', REPLACE(ids, ';', ','))
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.