Monday, May 11, 2015

[MySQL][sql] Select first four characters only from returned field

You can use the MySQL LEFT() function:

Syntax
LEFT (string, length)

Example:
SELECT date AS year FROM news


SELECT left(date,4) AS year FROM news 



Reference:
http://stackoverflow.com/questions/12504985/how-to-take-last-four-characters-from-a-varchar

2 comments :

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hello Xenia! How are you? It seems you are working on mysql and php

    ReplyDelete