Hello

BS> Thanks, I tried that and it gives no error, but only gives the first 
BS> lot, not the bit after the union all.

Ah. I hadn't tried with data. I don't know why the LIMIT affects the UNION 
ALL, when it is buried in a subquery. It doesn't affect a UNION (no ALL). 
In your real data and query, can a patient have more than one age? If not, 
then UNION and UNION ALL would produce the same results.

sqlite> create table table1 (patientID int, age int);
sqlite> insert into table1 (patientID, age) values (1, 50);
sqlite> insert into table1 (patientID, age) values (2, 50);
sqlite> insert into table1 (patientID, age) values (3, 50);
sqlite> insert into table1 (patientID, age) values (4, 50);
sqlite> insert into table1 (patientID, age) values (5, 50);
sqlite> insert into table1 (patientID, age) values (6, 50);
sqlite> insert into table1 (patientID, age) values (7, 50);
sqlite> insert into table1 (patientID, age) values (8, 60);
sqlite> insert into table1 (patientID, age) values (9, 60);
sqlite> insert into table1 (patientID, age) values (10, 60);
sqlite> insert into table1 (patientID, age) values (11, 60);
sqlite> insert into table1 (patientID, age) values (12, 60);

This seems to work:

select patientID 
from table1 
where patientID in (select patientID from table1 where age=50 limit 6) 
union all 
select patientID 
from table1 
where patientID in(select patientID from table1 where age=60 limit 4);

1
2
3
4
5
6
8
9
10
11

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

Reply via email to