4 Replies - 2069 Views - Last Post: 30 December 2010 - 10:12 PM Rate Topic: -----

#1 sidhu_sree  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 08-October 09

select number from varchar field in mysql db

Posted 30 December 2010 - 02:30 AM

Hello hi
Am new to php

i am using data base
with fields
/*------------------*/
companyid , companyname
/*----------------------*/
0 ,0aqua */
1 ,microsoft */
2 ,dell */
3 ,247indian */
/*----------------------*/

now i want to select company name that starts with number
output is like:-
////////////////
0aqua
247indian
365support

any reply the query related to get above out put

Is This A Good Question/Topic? 0
  • +

Replies To: select number from varchar field in mysql db

#2 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: select number from varchar field in mysql db

Posted 30 December 2010 - 03:22 AM

Haven't used RLIKE much, but I'd say that's what you're after. Try this out (of course, substitute in the name of your table):

SELECT companyname
FROM tablename
WHERE companyname RLIKE '^[0-9]'



EDIT: This should work too...

SELECT companyname
FROM tablename
WHERE companyname REGEXP '^[0-9]'



RLIKE uses the character set of the column, whereas REGEXP doesn't (I believe)

This post has been edited by e_i_pi: 30 December 2010 - 03:25 AM

Was This Post Helpful? 0
  • +
  • -

#3 sidhu_sree  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 08-October 09

Re: select number from varchar field in mysql db

Posted 30 December 2010 - 08:30 AM

View Poste_i_pi, on 30 December 2010 - 02:22 AM, said:

Haven't used RLIKE much, but I'd say that's what you're after. Try this out (of course, substitute in the name of your table):

SELECT companyname
FROM tablename
WHERE companyname RLIKE '^[0-9]'



EDIT: This should work too...

SELECT companyname
FROM tablename
WHERE companyname REGEXP '^[0-9]'



RLIKE uses the character set of the column, whereas REGEXP doesn't (I believe)

I have tried this but it is not working possible any other answer
Was This Post Helpful? 0
  • +
  • -

#4 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: select number from varchar field in mysql db

Posted 30 December 2010 - 09:00 AM

Check your table name. The code should be fine, I got this to work without any problems:

CREATE TABLE company
(companyid   INT NOT NULL PRIMARY KEY
,companyname VARCHAR(20)
);

INSERT INTO company(companyid,companyname) VALUES (0,'0aqua');
INSERT INTO company(companyid,companyname) VALUES (1,'Microsoft');
INSERT INTO company(companyid,companyname) VALUES (2,'Dell');
INSERT INTO company(companyid,companyname) VALUES (3,'247indian');
SELECT companyname FROM company WHERE companyname REGEXP '^[0-9]';


Was This Post Helpful? 0
  • +
  • -

#5 sidhu_sree  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 08-October 09

Re: select number from varchar field in mysql db

Posted 30 December 2010 - 10:12 PM

View Poste_i_pi, on 30 December 2010 - 08:00 AM, said:

Check your table name. The code should be fine, I got this to work without any problems:

CREATE TABLE company
(companyid   INT NOT NULL PRIMARY KEY
,companyname VARCHAR(20)
);

INSERT INTO company(companyid,companyname) VALUES (0,'0aqua');
INSERT INTO company(companyid,companyname) VALUES (1,'Microsoft');
INSERT INTO company(companyid,companyname) VALUES (2,'Dell');
INSERT INTO company(companyid,companyname) VALUES (3,'247indian');
SELECT companyname FROM company WHERE companyname REGEXP '^[0-9]';


I have tried but output is different
It is displaying all records from the table

for query SELECT companyname FROM company WHERE companyname REGEXP '^[0-9]';
out put is :-

0aqua
Microsoft
Dell
247indian
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1