Have the following table:

CREATE TABLE READCODE(
[SUBJECT_TYPE] TEXT,
[READ_CODE] TEXT,
[TERM30] TEXT,
[TERM60] TEXT,
[ENTRY_COUNT] INTEGER)

Records are ordered ascending on READ_CODE as the records are obtained
from an ordered array and inserted sequentially.
There is a non-unique index on Read code.

Now I need to run queries like this:

SELECT DISTINCT
READ_CODE, TERM30, TERM60, ENTRY_COUNT
FROM
READCODE
WHERE
TERM30 LIKE '%ANGINA%' OR TERM60 LIKE '%ANGINA%'

Now if I do this then the ascending order on READ_CODE is lost, so I
need to add an ORDER BY

However if I do this:

SELECT READ_CODE, TERM30, TERM60, ENTRY_COUNT
FROM
READCODE
WHERE
TERM30 LIKE '%ANGINA%'
UNION
SELECT READ_CODE, TERM30, TERM60, ENTRY_COUNT
FROM
READCODE
WHERE
TERM60 LIKE '%ANGINA%'

Then I get the required ascending order on READ_CODE. This looks good
as this query is some 50% faster.
However, I am not sure if I can rely on this order to always happen.
I take it that this an unintended outcome that might change in future versions?
Is this indeed the case?

RBS
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to