Subject Re: How do I write this query
Author Svein Erling Tysvær
That's easy, Grant, just do

SELECT DISTINCT A.<something>
FROM A
JOIN B ON B.<foreign key>=A.<primary key>
JOIN C ON C.<foreign key>=B.<primary key>
WHERE C.<field> = <value>

or (if you want duplicates of A, but not of B and C)

SELECT A.<something>
FROM A
WHERE EXISTS(
SELECT * FROM B
JOIN C ON C.<foreign key>=B.<primary key>
WHERE B.<foreign key>=A.<primary key>
AND C.<field> = <value>)

This should get you started,
Set

--- In firebird-support@yahoogroups.com, Grant Brown wrote:
> Hi everyone,
>
> Could some one help me write the following SQL query, once I see
> the basics I will be on my way.
>
> I have 3 tables set up as such
>
> Table A <<<>>> Table B<<< >>> Table C
>
> Table B is the detail Table of A where Table A is the master table
>
> Table C is the detail Table of B where Table B is the master table
>
> ie all 3 tables are related
>
> I need to find all records in Table A where the record in Table C =
> a value
>
> TIA
>
> --
> Regards,
> Grant Brown
>
> Product Development Manager
> Phone : 02 4229 1185
> Mobile : 0412 926 995
> Email : grant@s...
> Web : www.sitedoc.com.au
>
> SiteDoc - Easy to Use - Powerful Results