Andre Oosthuizen Andre Oosthuizen - 4 months ago 14
SQL Question

Mysql select part of field and return full value

Good day all,

I have a field called mCodes which has the exact length (7) throughout the table but with different values i.e. a few records with 5036100, 5036102, 5036103, 7010100, 7010101 etc.

I am using a select statement to first search for the first 4 characters i.e 5036 which will return all the records with 5036 just fine

I now need to return the actual full value of the records 5036100 etc. without recreating another sql statement. My statement I am using is as follow -

SELECT LEFT(MCODE, 4), MAKE, MODEL, NEWPRICE23 FROM mautogd1015 WHERE LEFT(MCODE, 4) = '5036'


I have racked my brain over this for a few hours now, any help will be appreciated.

Answer

Try something like this.

SELECT MCODE, MAKE, MODEL, NEWPRICE23 FROM mautogd1015 WHERE LEFT(MCODE, 4) = '5036'
Comments