order-by

Using [0] or First() with LINQ OrderBy

If I have a structure like this  Albums     - Album         - Discs             - Tracks and I want to order a collection of albums by the title of the first track on the first disc. Is there something similar to the following I could do (keeping in mind I need to use the OrderBy extension method that accepts a string)? alb...

Is it possible to refer to column names via bind variables in Oracle?

I am trying to refer to a column name to order a query in an application communicating with an Oracle database. I want to use a bind variable so that I can dynamically change what to order the query by. The problem that I am having is that the database seems to be ignoring the order by column. Does anyone know if there is a particula...

How to update and order by using ms sql

Hi, Ideally I want to do this: UPDATE TOP (10) messages SET status=10 WHERE status=0 ORDER BY priority DESC; In English: I want to get the top 10 available (status=0) messages from the DB and lock them (status=10). A message with a higher priority should be gotten first. unfortunately MS SQL doesn't allow an order by clause in the up...

order by case and alias

How can I use ORDER BY CASE @AccountOperator WHEN '>' THEN AccountTrxValue END ASC, CASE @AccountOperator WHEN '<' THEN AccountTrxValue END DESC when AccountTrxValue is an alias and a result of the following in the "select"? CASE WHEN PAA.RedeemValue>0 THEN PAA.RedeemValue * -1 ELSE PAA.EarnValue END AS AccountTrxValu...

What is the best way to sort a data table in ADO.NET

What is the best for sorting a data table in c#, both from a performance and a code-readability point-of-view: personsDT.OrderBy(person => person.PersonName); or: personsDT.DefaultView.Sort = "PersonName ASC"; The personsDT is build from a SharePoint list, so it is impossible to use SQL (I am aware that an ORDER BY claude in a SQL ...

NHibernate unexpected ORDER BY Statement

Hi, I am using NHibernate 2.0, and when I submit a request asking for the top 2 records to be returned, I get a number of ORDER BY clauses in my SQL. When I take out the Max results, the query looks fine (no ORDER BY statements). Why is NHibernate automatically adding this when I am looking for a subset of records? Thanks in advance ...

Get records ordered alphabetically starting by a certain letter in Sql Server

In SQLSERVER/MSSQL, here's the problem: SELECT * from [Translation Color] order by [Language Code] I want records ordered in alphabetical order starting by the 'I' letter. Example of result: 'Ioren' 'Iumen' 'Tart' 'Arfen' 'Coldry' I don't want to use union or more sql statements.. just try to catch it with an order by special claus...

Comparing Tuples in SQL

Is there any more convenient way to compare a tuple of data in T-SQL than doing something like this: SELECT TOP 100 A, B FROM MyTable WHERE (A > @A OR (A = @A AND B > @B)) ORDER BY A, B Basically I'm looking for rows with (A, B) > (@A, @B) (the same ordering as I have in the order by clause). I have cases where I have 3 fields, but it...

How do I order a Group result, in Linq?

Hi folks, I have the following linq query, which works fine. I'm not sure how i order the group'd result. from a in Audits join u in Users on a.UserId equals u.UserId group a by a.UserId into g select new { UserId = g.Key, Score = g.Sum(x => x.Score) } the results are currently ordered by UserId ascending. I'm after Score descending. ...

MS Sql: Conditional ORDER BY ASC/DESC Question

I want to to make to make the ordering in my query conditional so if it satisfiess the condition it should be ordered by descending For instance: SELECT * FROM Data ORDER BY SortOrder CASE WHEN @Direction = 1 THEN DESC END ...

MySQL: Selecting rows ordered by character count

In MySQL, how can I order my query by character count? ...

LINQ OrderBy help needed

Hi - I'm trying to create a collection of strings in an order defined by another array. Sounds confusing I know so let me explain requiredOrderOfElements{ [0] category1, [1] categoryX, [2] something else } my client passes up a string array containing the key and value ie passed from client { [0][0] categoryX, [0][1] value from Catego...

Linq Query with SUM and ORDER BY

I have a (C#) class called Hit with an ItemID (int) and a Score (int) property. I skip the rest of the details to keep it short. Now in my code, I have a huge List on which I need to do the following select (into a new List): I need to get the sum of all Hit.Score's for each individual Hit.ItemID, ordered by Score. So if I have the follo...

convert mysql stored procedure to mssql

Hi, I need to used dynamic order query in mysql and i have successfully achieved that through string concatenation in mysql as follows: set @stmt_text := concat('select * from abc order by ',sorder); prepare stmt_handle from @stmt_text; execute stmt_handle; deallocate prepare stmt_handle; i need a similar way to convert this in mss...

order by not working

I am using an objectdatasource with a gridview to get data from my orm class, but I cannot get it to order by properly. I am using the code below but it does not come up in descending order like I have specified below. What am I missing? Using subsonic 2.1 <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByP...

[DB2] ordering resultset ö together with o

I want to order a resultset. The columns which i want to use for ordering contain german umlauts like ö, ü and ä. I want column data with these sortet together with normal letters. Example: At it the Moment, the resultset is ordered like this: ABCOXYZÖ I want it to be ordered like this: ABCOÖXYZ Thanks ...

Ordering a MySQL Query by Most Common Words in a field

I've always wondered about this, and now a client is wondering whether it's feasable: I have a list of sports, broken down like such: Boys Ice Hockey Boys Tennis Girls Ice Hockey Girls Tennis ...etc And they want it to sort like: Boys Ice Hockey Girls Ice Hockey Boys Tennis Girls Tennis ...etc I'm just wondering if this i...

SQL: Using Top 1 in UNION query with Order By

I have a table as below Rate Effective_Date ---- -------------- 5.6 02/02/2009 5.8 05/01/2009 5.4 06/01/2009 5.8 12/01/2009 6.0 03/15/2009 I am supposed to find the all rates that are effective for current date and after it. So to get the current effective rate, i use SELECT TOP 1 * from table where effective_date < '05/05/2009...

Need some help ordering a Linq result.

Hi folks, I have some Linq code, that works fine. It retrieves a list of board posts ordered by the most recent. The catch here is the order by ... it orders by the most recent COMMENTS. So if a board post just got a comment, then it will be up the top of the list (ie. most recent). kewl ... but what about new board posts that just g...

ORDER BY with bool > date > null in SQLite

I have a loooooooooooong SELECT ending with a ORDER BY that can include the following values : checked (1 or 0) date (YYYY-MM-DD) time (HH:MM:SS) I'd like to order the result of the query the following way : |__checked = 0 | |__ date ASC | |__ time ASC | |__ date && time are null |__checked = 1 ...