Reputation: 6426
I have a column named emails which I have to sort.
The problem 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?
Upvotes: 0
Views: 85
Reputation: 16629
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"
Upvotes: 1
Reputation: 35842
I'm not familiar with ruby, but if you want to write SQL script, then this might help:
select columName from tableName where columnName != ''
Upvotes: 0
Reputation: 7661
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.
Upvotes: 2