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 != ''
精彩评论