PDA

View Full Version : select LEFT sql database


eksob
11-10-2005, 05:44 PM
I need the select statement that will select the first 3 characters of the field.

For instance:

Field1 = 123,345
Field2 = 123,980
Field3 = 234,487
Field4 = 456,1234
Field5 = 1234,7863

I want to select the first (LEFT) 3 characters that are equal to "123"...So technically Field1, Field2, Field5 would be retreived.

I am an avid programmer in PHP, learning ASP (server doesn't support .NET)...anyways this is what the select statement would look like in PHP:

SELECT id, name, LEFT(comments, 25) FROM comments ORDER BY cdate DESC LIMIT 5;

Thanks for the help in advance

Brandoe85
11-10-2005, 06:07 PM
All you're missing is the where clause:

select left(field, 3) from tbl where left(field, 3) = 123


Good luck;