Arringar1
Arringar1

Reputation: 415

Mysql select to get only part of a row from a column

I have a table with a column that contains a string of numbers and I only want to return the last couple of digits.

For example:

column1 | column2
_________________
Blah    | 1231357

I need a select that will return the last couple of digits from the second column.

Upvotes: 0

Views: 171

Answers (2)

Bill Karwin
Bill Karwin

Reputation: 562240

A modulus operator will take only the last two digits.

SELECT MOD(column2, 100) FROM mytable

Change 100 to 1000 to get three digits, etc.

Upvotes: 1

G-Nugget
G-Nugget

Reputation: 8836

Use the RIGHT function:

SELECT RIGHT(column2, 3) AS LastDigits FROM TableName

Change 3 to the number of digits you want.

Upvotes: 2

Related Questions