How do I specify the sort order?

This is the place to post technical queries about SQL Yoga

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, trevordevore

Post Reply
trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 908
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

How do I specify the sort order?

Post by trevordevore » Fri Oct 11, 2013 2:17 pm

[This post is an archive from the old SQL Yoga forums]

I have a table with noncontiguous integer values where I wish to return the row which has a value just less than my query.

i.e. if the rows had the following values: 1,3,6,9,12,17 and I queried on 8 I want to get back the row with the value 6.

I thus used a search on a GREATER OR EQUAL TO match, ordered the results and limited them to a single row.

However I need to order the results DESCENDING.

This orders the results -> sqlquery_set theQueryA,"order by", "nav_id"

But how do I specify DESC as the sort?

James
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 908
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: How do I specify the sort order?

Post by trevordevore » Fri Oct 11, 2013 2:17 pm

You should just be able to specify it in the "order by" property.

Code: Select all

sqlquery_set theQueryA,"order by", "nav_id DESC"
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 908
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: How do I specify the sort order?

Post by trevordevore » Fri Oct 11, 2013 2:17 pm

Ah. Perhaps the API could mention this. It currently just says the "order by" property only includes the fields to order by, nothing about being able to specify sort order. As it is (given I tend to ask questions on the weekend) I used rev's db calls to do it. I was sort of close though. I tried: sqlQuery_set theQueryA, "order by", "row_id" "DESC" For some reason I didn't think to include both the field and the sort order as a single string. :(
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

Post Reply

Return to “SQL Yoga”