Re: [sqlite] sorting two distinct groups

2013-02-05 Thread e-mail mgbg25171
Sorry for not responding sooner...unavoidably distracted... Yes one firm has many calls records... and you're looking for the time associated with the record of the LAST call you made to each firm. Having obtained these "latest call" times for each FIRM you then want to organise the firms in

Re: [sqlite] sorting two distinct groups

2013-02-04 Thread Igor Tandetnik
On 2/4/2013 2:40 AM, e-mail mgbg25171 wrote: Your query is extremely close but for the repetition of the c.ids at the end I'm not sure I understand. What is the relationship of "firms" and "calls" tables? Is it one-to-many (multiple calls for each firm)? If so, what is the meaning of

Re: [sqlite] sorting two distinct groups

2013-02-04 Thread e-mail mgbg25171
This seems to have answered part of my problem SELECT id FROM firms f left outer join (select firm_id from calls group by firm_id) c on f.id = c.firm_id order by firm_id On 4 February 2013 07:40, e-mail mgbg25171 wrote: > Igor > Thank you! > Your query is extremely

Re: [sqlite] sorting two distinct groups

2013-02-03 Thread e-mail mgbg25171
Igor Thank you! Your query is extremely close but for the repetition of the c.ids at the end I've tried putting group by (c,id) but got an error Indeed my weakness seems to be having little idea of how to insert the stuff for a single query into compound queries. e.g. If I want to introduce an

Re: [sqlite] sorting two distinct groups

2013-02-03 Thread Igor Tandetnik
On 2/3/2013 3:43 PM, e-mail mgbg25171 wrote: SELECT f.id FROM firms AS f WHERE f.id NOT IN (SELECT c1.firm_id FROM calls AS c1) OR f.id IS NULL union SELECT f2.id FROM firms AS f2 WHERE f2.id IN (SELECT c2.firm_id FROM calls AS c2) order by (c1.last is null, c2.last is not null) I have two

[sqlite] sorting two distinct groups

2013-02-03 Thread e-mail mgbg25171
SELECT f.id FROM firms AS f WHERE f.id NOT IN (SELECT c1.firm_id FROM calls AS c1) OR f.id IS NULL union SELECT f2.id FROM firms AS f2 WHERE f2.id IN (SELECT c2.firm_id FROM calls AS c2) order by (c1.last is null, c2.last is not null) I have two tables firms and calls. I'd like to list all the