How do I order by multiple columns in a SELECT query?
I have a table of records like below int_record_id int_category_id str_name int_order bit_active 1 1 test1 2 1 2 1 test2 1 1 3 2 test3 1 1 1 3 te...
I have a table of records like below int_record_id int_category_id str_name int_order bit_active 1 1 test1 2 1 2 1 test2 1 1 3 2 test3 1 1 1 3 te...
Is there any reason why or why not you should do an 'order by' in a subquery? ...
I'm trying to figure out how to sort a collection of documents server side by telling the C# driver what the sort order is, but it appears not to support that construct yet. Is it possible to do this any other way? ...
I'm getting an Entity Framework object collection from my Products table called oProducts. I am looping through the collection and setting the Quantity field from a separate function. Before I write out a display of the objects in HTML, I want to sort them by the Quantity. So, I am using LINQ to create a new collection and try to orde...
what is the linq equivalent of the following: SELECT Mytable.A, MyTable.B, SUM(MyTable.C) FROM MyTable GROUP BY Mytable.A, MyTable.B ORDER BY Mytable.A, MyTable.B This is trivial in SQL, but seems to be very difficult in LINQ. What am I missing? ...
This is kind of a noobish question, but it's one that I've never been given a straight answer on. Suppose I have a DB table with the following fields and values: | id | date_added | balance | +------------------------------------+ | 1 | 2009-12-01 19:43:22 | 1237.50 | | 2 | 2010-01-12 03:19:54 | 473.00 | | 3 | 2010-01-12 0...
Hi everybody, I have two tables storing members data members: id, field1, field2 and field3... members_extra: memberId, someExtraField1 and someExtraField2 members_extra.memberId is a Foreign Key referencing members.id 'members_extra' may or may not have related rows for rows in 'members' let's say: I have 1000 members in 'members...
I have a model for our customers and a model for their purchases/orders. In our backend/web admin, we want to be able to sort the customer list by their most recent order. Here is basically what our models look like class Customer(models.Model): username = models.CharField(max_length=32) first_name = models.CharField(max_length...
This query (part of a sproc) will be executed quite a lot: SELECT TOP (@numRecords) BlogPost.postId,BlogPost.creationDate, BlogPost.header,BlogPost.markedupContentAbstract FROM dbo.BlogPost ORDER BY BlogPost.creationDate DESC Should I put an index on the 'creationDate' field in the BlogPost table? Should I have a view wh...
I am new to mysql and I have been pulling my hair out about this problem for days. I need to improve/optimize this query so that it runs faster - right now its taking over 5 seconds. Here is the query: SELECT SQL_NO_CACHE COUNT(*) as multiple, a.*,b.* FROM announcements as a INNER JOIN stores as s ON a.username=s.username ...
Considering this MySQL query: SELECT someColumns FROM someTable WHERE someColumn IN ( value1, value2, value3 ) ... how can I guarantee that the rowset comes out ordered in the exact order of the values given to the IN () clause? I presume this is not guaranteed without giving it an ORDER BY clause, is it? PS.: The values to the...
Suppose I have a list of items (e.g., Posts) and I want to find the first item according to some non-trivial ordering (e.g., PublishDate and then CommentsCount as a tie-breaker). The natural way to do this with LINQ is like this: posts.OrderBy(post => post.PublishDate).ThenBy(post => post.CommentsCount).First() However, the micro-opti...
My data has been placed into an array, but unfortunately not in the order I want it in... String[][] databaseToArray = { //{"Name", "Channel", "Description", "Amount", "isReady"}, {"John", "Nick", "likes", "2", "yes" }, {"Drew", "MTV", "dislikes", "4", "no" }, {"Fred", "CNN", "okay", ...
I have a table with store IDs and the city where the store is located. I want to list all the stores starting with the stores that are in the city where there is the most stores. TABLE ID CITY 1 NYC 2 BOS 3 BOS 4 NYC 5 NYC The output I want is the following since I have the most stores in NYC, I want all the N...
Working with four tables. Users -> has basic user info including a userid and a departmentid (int) Groups -> basic group info including a groupid GroupsMembers -> table that has the relationship between a group and it's members, many to many relationship, so groupid and userid are the columns Departments -> basic department info includi...
Is it possible to set the default order-by column to use in the NHibernate mapping file? Unless explicitly defined I want to order all specific entities by the Name column automatically. I've seen that it can be done on collections but thats not what I'm after in this case. ...
I have an NAnt task "ship" to package my current .sql scripts into a build, then name the build with an incrementing int {######} and copy it to a build folder. I have another NAnt task which executes those build scripts. They must execute in order, but in my last attempt, they were not. Can I "force" NAnt to work alphabetically? Tha...
I have a mix of greek and normal words and now the order of these is that the normal words comes first and then all the greek words. I want them to get mixed in the order so beta in greek is the same as B. How can I make this ORDER BY in SQL Server? ...
I have a scenario, which is seemingly simple on paper, but I'm having trouble getting to work as desired in practice. I have two tables (only relevant columns presented): | Thread +---------- | ThreadID | Post +---------- | PostID | ThreadID | Posted (Datetime) Now, what I want to do, is to join Thread and Post, grouping by ThreadI...
Hi All, I would like to know if its possible to order by a specific ID in subsonic 2.1. Same as regular sql query: ORDER BY CASE WHEN ID = 5 then 1 WHEN ID = 10 then 2 WHEN ID = 1 then 3 WHEN ID = then 4 else 5 END I hope someone can help me, I want this functionality for country specific content. Kind regards, Mark ...