Mahesh
Mahesh

Reputation: 6426

How do I neglect blank strings in sorting?

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

Answers (3)

sameera207
sameera207

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

Saeed Neamati
Saeed Neamati

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

Szocske
Szocske

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

Related Questions