开发者

How do I neglect blank strings in sorting?

开发者 https://www.devze.com 2023-03-17 11:27 出处:网络
I have a column named emails which I have to sort. The pr开发者_如何学编程oblem is there are some blank strings in the db which appear in front.

I have a column named emails which I have to sort.

The pr开发者_如何学编程oblem is there are some blank strings in the db which appear in front.

I don't want to include these blank strings '' while sorting.

How can I do this?


Exclude them from the database query result set by adding a WHERE condition to your SQL query. What database management system are you using? BW sorting is usually most efficient when done by the database, use ORDER BY in SQL.


As a best practice avoid blanks strings in your selection SQL.

Use a :scope or :named_scope (depending on your Rails version) and do something like this

:conditions => "email !=''", :order => "email"


I'm not familiar with ruby, but if you want to write SQL script, then this might help:

select columName from tableName where columnName != ''
0

精彩评论

暂无评论...
验证码 换一张
取 消