I seem to have stumbled on a bug in SQLite.

create table Campaigns (id integer primary key, accountId integer, name varchar);
create table CampaignStats (id integer primary key, campaignId integer);
insert into Campaigns values(1, 1, 'A');
insert into Campaigns values(2, 1, 'B');


select c.*
from Campaigns c join (select 1) on (accountId=1)
    left join CampaignStats cs on (c.id = cs.campaignId);

1|1|A
2|1|B


select c.*
from Campaigns c join (select 1) on (accountId=1)
    left join CampaignStats cs on (c.id = cs.campaignId)
order by c.name;

<no rows returned>


It seems a combination of "join (select 1)" (admittedly weird, but there are reasons I would like to be able to do this), "left join" and "order by" confuses the engine. Removing any one of the three makes the query work as expected.

Running SQLite 3.2.7 on Windows, from precompiled binaries.

Igor Tandetnik

Reply via email to