Using above code, it gives result with order of author_year based on author names. I need to order the query ascendingly based on the year which presents in author_year. and I wish to print the oldest data based on the year not ordered by author name. Kindly give me some suggestion on this issue.
Refactor the DB to have those fields available separately. You have two
distinct pieces of data munged together in one field.
I shouldn’t edit or modify the data in database. The data has not munged. The default data field is created with two pieces. In general author referencing, the data will be included with year and author name. Author name and year are the two pieces in author_year column. Kindly tell me if functions available to sort SQL query output with second piece only as sorting element.
I shouldn't edit or modify the data in database. The data has not munged.
The default data field is created with two pieces. In general author
referencing, the data will be included with year and author name. Author
name and year are the two pieces in author_year column. Kindly tell me if
functions available to sort SQL query output with second piece only as
sorting element.
If you really want to ignore what others have said the :order options
takes an sql fragment. SQL has some string manipulation functions so
you can probably come up with a way of extracting the year from that
column, but such a query wouldn't be able to use any indexes to help
with the ordering so you might end up with something slow as well as
something yucky.
You’re defining author_yr in a ruby model, but expecting the DATABASE to
know what that is. Doesn’t work that way.
As Fred mentioned, you need to use a database function that looks at the
“author_year” field (the last 4 characters) to order upon.
I got your point. I will look for last 4 character to order up in database function. thank you for suggestion.