MySQL在order by子句之前删除空间 [英] MySQL remove space before order by clause

查看:108
本文介绍了MySQL在order by子句之前删除空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充满"title"的表格,我想按标题排序.问题是其中许多标题前都有空白.我正在考虑编写一个php脚本来修复所有问题(超级简单),但我很好奇我该怎么做:

I have a table full of "title" that I want to order by title. Problem is a lot of them have a empty space before the title. I am thinking of writting a php script to fix it all (super easy) but I was curious how could I do:

SELECT * FROM products ORDER BY title

但是同时修整标题,以使它不会在空白处排序.全部都在同一查询中而不更改数据.上帝,我希望我有道理.

But at the same time trimming the title so it doesnt order on the empty space. All in the same query without changing the data. God I hope I make sense.

所以我真的在寻找一个mysql解决方案.对于什么价值,我使用Zend_Db,所以使用它的解决方案会更好,但我可以管理直接的MySQL.

So I am really looking for a mysql solution to this. For what its worth I use Zend_Db so a solution using that would be even better but I can manage straight MySQL.

推荐答案

您可以使用TRIM函数:

You can use the TRIM function:

SELECT TRIM(title) as title, field2, field3 FROM products ORDER BY TRIM(title)

那应该做到的!

这篇关于MySQL在order by子句之前删除空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆