Cutting data via sql query
I want to write similar to "click for more".
I cant remember this tech. I could via sql query. I开发者_Python百科 want to select data's first 30 character.
How?
Every SQL flavor I've worked with has a substring function:
Oracle, MySQL, PostgreSQL, SQLite:
SELECT SUBSTR(column, 1, 30) FROM table;
SQL Server, MySQL:
SELECT SUBSTRING(column, 1, 30) FROM table;
Alternatively, you can make use of the LEFT
function, which is supported by some of these DBs:
MySQL, SQL Server:
SELECT LEFT(column, 30) FROM table;
And of course you can use a column alias, like:
SELECT SUBSTR(column, 1, 30) AS partial FROM table;
SELECT SUBSTRING(column, 1, 30) AS partial FROM table;
In mysql string start point is 1 so you should use
SELECT SUBSTR(column, 1, 30) FROM table;
SELECT LEFT(Data,30) FROM MyTable
精彩评论