Subject | Help on Join Please |
---|---|
Author | cornievs |
Post date | 2011-08-01T00:54:22Z |
I have 2 tables that I need to join with a third table defining a linked between the 2.
CLIENTS A
CODE VARCHAR(15) (PK)
NAME VARCHAR(30)
.
.
CLIENT_GROUPS B
CODE VARCHAR(15) (PK)
DESCRIPTION VARCHAR(30)
CLIENT_GROUPING C
GROUPING_CODE (PK) (Links to CODE in B CLIENT_GROUP)
CLIENT_CODE (PK) (LINKS to CODE in A CLIENTS)
What I need is SELECT result with each and everyone record of B CLIENT_GROUPS only once, plus a FIELD (call it LINKED) which indicates if there is record in CLIENT_GROUPINGS where C.GROUPING_CODE = B.CODE and C.CLIENT_CODE = 'xyz client'
Example Data
CLIENTS
CODE NAME
John John Murray
Mary Mary Poppins
CLIENT_GROUPS
CODE DESCRIPTION
Every Everyone
OT18 Older Than 18
CLIENT_GROUPINGS
GROUPING_CODE CLIENT_CODE
Every John
Every Mary
OT18 John
Required result when C.CLIENT_CODE = 'Mary'
GROUP_CODE LINKED
Every True or 1 or not null
OT18 False or 0 or null
Any help will be much appreciated.
Regards
Cornie van Schoor
CLIENTS A
CODE VARCHAR(15) (PK)
NAME VARCHAR(30)
.
.
CLIENT_GROUPS B
CODE VARCHAR(15) (PK)
DESCRIPTION VARCHAR(30)
CLIENT_GROUPING C
GROUPING_CODE (PK) (Links to CODE in B CLIENT_GROUP)
CLIENT_CODE (PK) (LINKS to CODE in A CLIENTS)
What I need is SELECT result with each and everyone record of B CLIENT_GROUPS only once, plus a FIELD (call it LINKED) which indicates if there is record in CLIENT_GROUPINGS where C.GROUPING_CODE = B.CODE and C.CLIENT_CODE = 'xyz client'
Example Data
CLIENTS
CODE NAME
John John Murray
Mary Mary Poppins
CLIENT_GROUPS
CODE DESCRIPTION
Every Everyone
OT18 Older Than 18
CLIENT_GROUPINGS
GROUPING_CODE CLIENT_CODE
Every John
Every Mary
OT18 John
Required result when C.CLIENT_CODE = 'Mary'
GROUP_CODE LINKED
Every True or 1 or not null
OT18 False or 0 or null
Any help will be much appreciated.
Regards
Cornie van Schoor