B
Bonnie
Please Help: There must be a SQL solution to retrieve the youngest and only
siblings. I thought this query would be pretty straight forward but
apparently NOT. Everything I tried fails to extract the correct result set.
Environment: MS ACCESS 2003 pass-through query to a MS SQL Server 2000 DB.
Criteria: Select students without any siblings (SIBLING_CODE IS NULL OR
='') and only the youngest sibling of a family MAX(BIRTHDATE). Note:
Siblings will have a unique
family number. Siblings could be a twins with same birthdate SELECT
MIN(PERSON_ID).
Members of a family may have different surnames. GROUP BY SIBLING_CODE but
also select the PERSON_ID for other multiple table links.
PERSONS table with select fields defined:
PERSON_ID (varchar (13) Unique not null)
SIBLING_CODE (number (9)(13,0) NULL)
SURNAME (varchar (40) not null)
FIRST (varchar (20) not null)
BIRTHDATE (DATETIME (8) null)
..
..
..
Sample data:
PERSONS table
PERSON_ID | SIBLING_CODE | SURNAME | FIRST | BIRTHDATE
-------------------------------------------------------
100 |1 | Doe | John | 1996-01-01
200 |1 | Doe | Sally | 2000-02-01
300 |<NULL> | Smith | Jane | 1999-02-03
400 |2 | Twins | Joe | 2000-12-25
500 |2 | Twins | Moe | 2000-12-25
600 |2 | G-Twins | Bill | 1997-09-05
siblings. I thought this query would be pretty straight forward but
apparently NOT. Everything I tried fails to extract the correct result set.
Environment: MS ACCESS 2003 pass-through query to a MS SQL Server 2000 DB.
Criteria: Select students without any siblings (SIBLING_CODE IS NULL OR
='') and only the youngest sibling of a family MAX(BIRTHDATE). Note:
Siblings will have a unique
family number. Siblings could be a twins with same birthdate SELECT
MIN(PERSON_ID).
Members of a family may have different surnames. GROUP BY SIBLING_CODE but
also select the PERSON_ID for other multiple table links.
PERSONS table with select fields defined:
PERSON_ID (varchar (13) Unique not null)
SIBLING_CODE (number (9)(13,0) NULL)
SURNAME (varchar (40) not null)
FIRST (varchar (20) not null)
BIRTHDATE (DATETIME (8) null)
..
..
..
Sample data:
PERSONS table
PERSON_ID | SIBLING_CODE | SURNAME | FIRST | BIRTHDATE
-------------------------------------------------------
100 |1 | Doe | John | 1996-01-01
200 |1 | Doe | Sally | 2000-02-01
300 |<NULL> | Smith | Jane | 1999-02-03
400 |2 | Twins | Joe | 2000-12-25
500 |2 | Twins | Moe | 2000-12-25
600 |2 | G-Twins | Bill | 1997-09-05