比如test表,设置uid和wid为主键
CREATE TABLE test
(
uid INTEGER NOT NULL,
wid INTEGER NOT NULL,
incorrect SMALLINT,
CONSTRAINT pk PRIMARY KEY(uid, wid)
)添加如下数据(incorrect不管它,设为空):
uid wid incorrect
1 3
1 7
1 6
1 8
1 9
2 2
2 4
2 10
2 7
2 6当我用以下语句
SELECT *
FROM test
WHERE uid = 1;查询时,结果竟然是wid排好序的
uid wid incorrect
1 3
1 6
1 7
1 8
1 9
不设联合主键,或者不加WHERE uid = 1这句都不会出现自动排好序的情况
不知道是神马情况,我用的SQLITE,不可以用order by charindex这种东东

解决方案 »

  1.   

    查询出来的结果默认应该是升序。
    Lz说SQLITE里面不可以用order by,不可能吧,我这边一直都可以用
      

  2.   

    不是不可以用 ORDER BY
    而是不可以用SQL SERVER 的 ORDER BY charindex(....)
    (SQL SERVER里面,可以用上面的办法解决)我想按插入数据的顺序取得数据,而不要已经排好序的
      

  3.   

    charindex是SQL SERVER自定义的函数,不是所有数据库都通用。
      

  4.   

    If a SELECT statement that returns more than one row does not have an ORDER BY clause, the order in which the rows are returned is undefined. Or, if a SELECT statement does have an ORDER BY clause, then the list of expressions attached to the ORDER BY determine the order in which rows are returned to the user. Rows are first sorted based on the results of evaluating the left-most expression in the ORDER BY list, then ties are broken by evaluating the second left-most expression and so on. The order in which two rows for which all ORDER BY expressions evaluate to equal values are returned is undefined. Each ORDER BY expression may be optionally followed by one of the keywords ASC (smaller values are returned first) or DESC (larger values are returned first). If neither ASC or DESC are specified, rows are sorted in ascending (smaller values first) order by default. 
      

  5.   


    如果把这句去掉
    CONSTRAINT pk PRIMARY KEY(uid, wid)
    就不会自动排序了(而会让插入数据时的顺序)这个是标准SQL里面规定的吗???