By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,165 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,165 IT Pros & Developers. It's quick & easy.

hwo to use REGEXP to find rows with any numbers in between?

100+
P: 170
hey guys,

i got a question on REGEXP in SQL

if i have a row containing the info

NAME : 12344455667678

how can i use a SELECt with REGEXP
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM `mml log` WHERE Commands REGEXP 
  2.  
such that it will search anything in the field with NAME : $input
in which the $input is given by my users

so say is $input is 234 or 444 or 5566
it will still return me the row containing the info above?
Jun 4 '08 #1
Share this Question
Share on Google+
8 Replies


10K+
P: 13,264
You don't need REGEXP for that. Just a simple like with the % wildcard will do.
If you insist on REGEXP then you can read about how to use it from here.
Jun 4 '08 #2

100+
P: 170
hm...i tried using wild card too

the reason why it doesn't work is 'cos
i want to make sure the number is attached to NAME

so if i have 2 rows each containing;

NAME :11223345565
CLASS: 18373556879


if i use use wild card with %556%
it's gonna return both the rows
but i only want it attached with NAME
Jun 4 '08 #3

10K+
P: 13,264
hm...i tried using wild card too

the reason why it doesn't work is 'cos
i want to make sure the number is attached to NAME

so if i have 2 rows each containing;

NAME :11223345565
CLASS: 18373556879


if i use use wild card with %556%
it's gonna return both the rows
but i only want it attached with NAME
I'm missing something here.
Are NAME and CLASS two different columns?
Jun 4 '08 #4

10K+
P: 13,264
I'm missing something here.
Are NAME and CLASS two different columns?
Wait, I think I get you now.
You can use concat. Concat 'NAME' with the wild carded input.
Jun 4 '08 #5

Atli
Expert 5K+
P: 5,058
If you have "NAME :11223345565" in a single field, you shouldn't!
You should never have two pieces of data inside the same field.
Check out this article.

If that is how it is tho, you could simply do:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM tbl WHERE col LIKE "NAME: %345%"
The wild-cards can be anywhere inside a string, not just at the ends.
Jun 4 '08 #6

10K+
P: 13,264
..
You should never have two pieces of data inside the same field.
...
Amen .
Jun 4 '08 #7

100+
P: 170
hm.i get what u mean
by right it should be under a column name

actualli that field of mine is called commands
commands that ppl use during a telnet session
sometimes commands can be very long with number
and i just wanna query say wildcard the number and get the results

with regards to
Expand|Select|Wrap|Line Numbers
  1.  
  2. NAME = %345%
  3.  
i've tried and doesn't worked too..
Jun 5 '08 #8

10K+
P: 13,264
hm.i get what u mean
by right it should be under a column name

actualli that field of mine is called commands
commands that ppl use during a telnet session
sometimes commands can be very long with number
and i just wanna query say wildcard the number and get the results

with regards to
Expand|Select|Wrap|Line Numbers
  1.  
  2. NAME = %345%
  3.  
i've tried and doesn't worked too..
Wildcards are used with the LIKE operator not the = operator.
Also I think you want to do
Expand|Select|Wrap|Line Numbers
  1.  LIKE 'NAME:%345%'
Jun 5 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.