tags:

views:

92

answers:

1

Hello.

Recently i found that SQLite don't support DISTINCT ON() clause that seems postgresql-specific. For exeample, if i have table t with columns a and b. And i want to select all items with distinct b. Is the following query the only one and correct way to do so in SQLite?

select * from t where b in (select distinct b from t)

Sample data:

a | b
__|__
1   5
2   5
3   6
4   6

What i expect in return:

a | b
__|__
1   5
3   6
+3  A: 

Use:

  SELECT MIN(t.a) AS A,
         t.b
    FROM TABLE t
GROUP BY t.b
OMG Ponies