Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread SQL statement
Mon, Mar 23 2009 4:44 PMPermanent Link

andrej
Have a classic master/detail situation for documents. I need a query with a following
result: for a chosen document, I need to know for each detail if there are details of same
kind followed the detail on the chosen document. In other words: if there are no details
of same kind(on other documents) which are on a chosen document, then the result is an
empty query.
ps. let say that "same kind" means that they have same code.
please advise

Tue, Mar 24 2009 7:19 AMPermanent Link

"John Hay"

andrej
> Have a classic master/detail situation for documents. I need a query with
a following
> result: for a chosen document, I need to know for each detail if there are
details of same
> kind followed the detail on the chosen document. In other words: if there
are no details
> of same kind(on other documents) which are on a chosen document, then the
result is an
> empty query.
> ps. let say that "same kind" means that they have same code.

I am not completely sure what you are after.  If you have a table structure
like the following and want all detail records that  have the same
detailcode as occur in the detail records of a particular master (eg 123)
then

MasterTable
MasterId
....

DetailTable
MasterId
DetailCode
....

SELECT * FROM DetailTable WHERE MasterId <> 123 and
DetailCode IN (SELECT DetailCode FROM DetailTable WHERE MasterId=123)

John

Image