e-mail mgbg25171 <[email protected]> wrote:
> I've only just discovered that you can get rows for foreign keys doing this
> 
> SELECT f.*
>    FROM firms f
>        inner JOIN calls c
>            ON f.id = c.firm_id group by c.firm_id;

I don't quite understand this query. What is the purpose of joining with calls 
table when you don't actually read any columns from it? Are you just trying to 
select all firms for which calls exist? That can be done more explicitly with 
something like

select * from firms where id in (select firm_id from calls);

> what if the foreign keys are from different flelds in different tables
> all unioned together

I'm still not sure I understand. Are you saying you have several calls tables, 
and you want all firms for which calls exist in at least one such table? 
Something like this perhaps:

select * from firms
where id in (select firm_id from calls1)
or id in (select firm_id from calls2);

-- or

select * from firms where id in (
    select firm_id from calls1
    union
    select firm_id from calls2);

-- 
Igor Tandetnik


_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to