tags:

views:

29

answers:

2

I have a table in a MySQL database that I am running simple SELECT queries on (for quick diagnostics/analysis - since I am not running phpmyadmin on the server - for security reasons).

I would like to be able to truncate the returned data using something like this:

select id, LEFT(full_name, 32), age FROM user

where user is a table that contains the columns id, full_name and age

I tried the above statement and it didn't work. anyone knows how to do this?

[Edit]

Sorry, when I said it dosen't work, I mean mySQL simply returns the STRING "LEFT(full_name, 32)" as an alias for the column 'full_name' and outputs the field value - which in this case, can be as long as 256 chars.

A: 
select id, SUBSTRING(full_name,1, 32), age FROM user 
Fosco
this returns an empty string: `SELECT LENGTH(SUBSTRING("abcd",0,3))` returns `0`
mvds
updated to start at 1
Fosco
now it's a duplicate ;-)
mvds
+1  A: 
select id, SUBSTRING(full_name,1, 32), age FROM user

quoting mysql.com:

For all forms of SUBSTRING(), the position of the first character in the string from which the substring is to be extracted is reckoned as 1.

mvds
As pointed out by Mark Baker in the comments above, an alias on the SUBSTRING would be a good idea
Brendan Bullen