order-by

SQL Server 2005 import a csv file , rows in correct order

I use SQL Server wizard to import csv files, however the rows imported appears in different order. How can I say to SQL Server to import rows in correct order. ...

ASP.NET / SQL drop-down list sort order

I am trying to correct the sort order of my ASP.NET drop down list. The problem I have is that I need to select a distinct Serial number and have these numbers organised by DateTime Desc. However I cannot ORDER BY DateTime if using DISTINCT without selecting the DateTime field in my query. However if I select DateTime this selects eve...

mysql order by issue

if i have a query like : SELECT * FROM table WHERE id IN (3,6,1,8,9); this array of the ids is build in php dynamically , and the order is important to me. $my_array = array (3,6,1,8,9) ; how can i sort the results by the order by which the elements appear in my array ? its possible to do it in MYSQL query, or i must to order it...

Linq to SQL provides different results when using TOP and Between

Hi, I'm using Linq to Sql (in fact it's Dynamic Linq to SQL that allows you to pass strings at runtime for where clauses, orderby etc.) But I'm getting some different results and it seems to be based on whether the underlying T-SQL is using the TOP keyword or using BETWEEN. I've tried to the break the problem down into a small example,...

Why does added RAND() cause MySQL to overload?

OK I have this query which gives me DISTINCT product_series, plus all the other fields in the table: SELECT pi.* FROM ( SELECT DISTINCT product_series FROM cart_product ) pd JOIN cart_product pi ON pi.product_id = ( SELECT product_id FROM cart_product po WHER...

Linq To Sql - Dynamic OrderBy - Case When

Hello, I'm using Linq to sql and Linq Dynamic OrderBy. I know linq dynamic can do simple sorting like - orderby("column_name"). But does it support something more complex like queries with "CASE WHEN" in them ? string orderbyQuery = "(CASE WHEN (username == 100) THEN 1 ELSE 0 END) DESC)"; here is my query : var u = from u in db.us...

Is StringComparer.CurrentCulture the right choice to use in this case?

I have a list of UTF-8 strings that I want to sort using Enumerable.OrderBy. The strings may contain any number of character sets - e.g., English, German, and Japanese, or a mix of them, even. For example, here is a sample input list: ["東京","North 東京", "München", "New York", "Chicago", "大阪市"] I am confused as to whether using String...

Using Hibernate to 'order by' a column which having a expression(sum, max, ...)?

select CONTRACT_ID, sum(PO_SPEND) from V_CONTRACT_ANALYSIS_202 group by CONTRACT_ID order by sum(PO_SPEND) desc ...

MySQL: ORDER BY stat / age?

I have an int field in my product table called product_stat which is incremented everytime a product is looked at. I also have a date field called product_date_added. In order to figure out the average visits per day a product gets, you need to calculate how many days the product has existed by using the current date and the date the p...

sortedArrayUsing and NSComparison Result : I don't understand how these are actually going about sorting

We're looking at different methods to sort the objects/elements in an array, the thing that doesn't make sense to me is how the actual sorting is done. I guess the big point of confusion is how can the "sort" method be effective if it only compares one object against another? If there are values a, g, b, d, z, s, h in the array im not ...

How does sql server sort your data?

Hello, I was wondering how sql server sorts it's data. I noticed that if I have a table that doesn't contain the column "Id" and you select data without "ORDER BY" sql server doesn't automatically sort on the primary column. Does anyone know what rule sql server follows to sort it's data? Regards, M. ...

Sorting Float Column vs Int Column in SQL Server

I wonder if type of a column matters in terms of sorting performance. I have heard that int columns are sorted faster than float columns. Do you think it is correct? ...

SQL multiple column ordering

I am trying to sort to multiple columns in SQL, and in different directions. coloumn1 would be sorted decending, and coloumn2 accending. How can I do this? ...

MySQL Orderby a number, Nulls last

Hi, Currently I am doing a very basic OrderBy in my statement. SELECT * FROM tablename WHERE visible=1 ORDER BY position ASC, id DESC The problem with this is that NULL entries for 'position' are treated as 0. Therefore all entries with position as NULL appear before those with 1,2,3,4. eg: NULL, NULL, NULL, 1, 2, 3, 4 Is there a w...

ordered SQL Select columnwise distinct but return of all columns

I have a little SQL Distinct puzzle that i cannot solve (or at least not in an very elegant way). I have two tables (try to ignore the simplicity of the example). I'm using MSSQL 2008 if that makes much of a difference. Table: Category | categoryId (uniqueidentifier) PK | | Name varchar(50) | Table: Download | do...

MySQL Orderby a number, Empty Strings (or 0's) Last

Hi, Just asked a question pretty similar to this one... Currently I am doing a very basic OrderBy in my statement. SELECT * FROM tablename WHERE visible=1 ORDER BY position ASC, id DESC The problem with this is that empty string entries for 'position' are treated as 0. Therefore all entries with position as empty string appear befor...

Strange MySQL GROUP BY/ORDER BY behaviour

SELECT p.price, h.name AS hotel_name FROM prices p LEFT JOIN hotels h ON p.hotel_id = h.id WHERE p.city = 'boedapest' AND p.hotel_id IS NOT NULL GROUP BY p.name ORDER BY p.price ASC RESULT: 26 Eben Hotel Budapest 27 Ve...

Dynamic order by in JPA/Hibernate?

The naive attempt query would look like this: Query query = em.createQuery("from org.domain.Resource r where r._parent = ? order by ?"); This does not work as the parameters should be data and not column names or syntax like ASC or DESC. What kind of workarounds you have figured out for this dynamic ordering? Concatenating the orderi...

OrderBy and Top in LINQ with good performance

What is a good way to get the top 10 records from a very large collection and use a custom OrderBy? If I use the LINQ to Objects OrderBy method it is slow and takes a lot of memory because it creates an entire new collection with the new order. I would like a new method with the signature below that does not re-order the entire collect...

List<> OrderBy IComparer ?

Hi guys, I have a List<ListViewItem> and I've used it in a ListView in VirtualMode There are 5000 items in the list and I'm gonna sort it with LINQ and OrderBy whenever a Column of the ListView is clicked , so I have written below code : List<ListViewItem> ListOfItems = new List<ListViewItem>(); ListViewColumnSorter lvwColumnSorter; ...