Subject Re: [IBO] SQL Help
Author Helen Borrie
At 07:11 AM 31/01/2008, you wrote:
>I want to add a column to a TIB_Grid that is currently displaying the
>contents of table A via an TIB_Query. The new column is from table B
>which is linked to A with a foreign key.
>
>The problem is that there isn't necessarily a record in table B
>corresponding to each item in A. Also there may be multiple B items
>corresponding to an A item. If I do a join, I don't see the A items
>that lack an entry in B.


>If I do a left join, I get multiple rows for the A items that have multiple B entries.

That's true. :-) The purpose of a join is to "flatten" the data stored in multiple related tables. Inner joins exclude any combination for which there is no match. Outer joins include combinations by one of 3 rules. The left join rule dictates that the set will have at least one row for each row in the "left" table, whether matching links exist or not; and multiple rows for each match that exists. Join logic *alone* can't give you a set that represents a 1:many relationship as an exclusive set comprising all and only unique master records.

If you want to represent this relationship so that your UI sees the "master records" in table A and can reach all of the linked "detail" records in table B, then do a single-table query for A and another single table query for B, that includes the FK columns, and link the two sets in a master-detail relationship.

If you would explain how you want to use this dependent column, we could get closer to a suggestion of how to implement it.

Helen