Search code examples
sqlsql-server-ce

SQL CE: Select distinct, order by another column


I'm trying to figure out how to order my data that I get, I want to do a select distinct(name) and order by ID like this:

var querythis = "SELECT distinct(exerVariName) as variants FROM Test WHERE date = @0 ORDER BY ID";

So I somehow have to select distinct(id) as well, is this possible to achieve?


Solution

  • Try this:

    select exerVariName as variants,
        MIN(ID) as min_id
    from Test
    where date = @0
    group by exerVariName
    order by min_id