1

I insert some data into test table.

C:\>  sqlite3 e:\\test.db
sqlite> create table test(code TEXT,content  numeric);
sqlite> insert into test(code,content)values('x',3);
sqlite> insert into test(code,content)values('x',1.5);
sqlite> insert into test(code,content)values('x',1);
sqlite> insert into test(code,content)values('y',9);
sqlite> insert into test(code,content)values('y',3);
sqlite> insert into test(code,content)values('y',2);
sqlite> insert into test(code,content)values('y',12.3);
sqlite> insert into test(code,content)values('y',11.5);

how can i get the ordered output as the following ?
select * from test group by code order by content;can not get it. select * from test order by content;neither.

x|1
x|1.5
x|3
y|2
y|3
y|9
y|11.5
y|12.3
showkey
  • 482
  • 42
  • 140
  • 295
  • If you want to have the results in time order, like most recent first, or oldest first, then you need to add an automatic timestamp to your table. See http://stackoverflow.com/questions/14461851/how-to-have-an-automatic-timestamp-in-sqlite – Paul Jun 02 '14 at 07:55

1 Answers1

0

You can sort by multiple criteria:

SELECT * FROM test ORDER BY code, content;
laalto
  • 150,114
  • 66
  • 286
  • 303