Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expression

Status
Not open for further replies.

4181944

Programmer
Aug 6, 2002
9
NZ
Hi All,

Can someone tell me how to use query to find or group records which using regular expression in MySQL?

eg. tableID = from 0001 to 9999

1) I want to find all records that match tableID the first and the third is digit 1.(eg: 1017,1717, 1614......), if i use query below ,

select * from tablename where tableID in ( tableID REGEXP "^1.1.")

only return me tableID =1 .

2) how to group records by tableID which are all the third digit is 1, ( eg: 2212, 3313,7412...) or all the second digit is 1 (e.g 2122, 3133,8153....)

TIA

Richard

 
1) select * from table where tableid like '1_1%';

2) I'm not sure if you want to group or order by, seems order by would be a better option as if the record ID's are unique you'll have a lot of recoreds grouped by themselves.

SELECT * FROM tablename where tableID like '1_1%' order by tableID;
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top