Is it possible to edit the contents of fields after a select statemen? For example, I have a table Person (Id int, Username varchar(50)). Most of the rows in Username has the format of, say for example, aaa_01, bbb_02. I want to select this usernames with the underscores and the numeric parts ommited (Say for aaa_01, it will output aaa only). Is this possible in mysql?

Thanks guys.

Recommended Answers

All 3 Replies

Hi,
you may try this:

select 'aaa_01' as st, left(st, locate ('_', st)-1) as shorter
-- st       shorter
-------------------
-- aaa_01   aaa

-- however, code not tested. you should look-up left and locate functions from mysql manual whether
-- the parameters are in correct sequence (mysql has its own notion on how to put the parameters in 
-- sequence)

-- Also this should work (parameters are in correct sequence now for instr() had been copied 
-- from Oracle):

select 'aaa_01' as st, left(st, instr(st, '_')-1) as shorter

-- tesu

@tesu

There was a bit of a problem in the syntax but after some fix it worked! Thank you very much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.