On 04-Apr-2012 07:19 , Dave wrote:
<<SNIP>> I was trying to actually show the results in
the same format as the original table, ie, like this :

client, child's date of birth

The original reply from Paul [under the original "Subject: Sql muddle"] gave the most direct answer with that effect, albeit written with two names for the client column and having used an "AGE" column versus a "DOB" (Date Of Birth) column. Rewritten, it would look like:

FROM theTABLE orig
WHERE EXISTS ( SELECT '1' /* client has a child > 20 years */
FROM theTABLE gt20
AND year(current date - gt20.DOB) > 20 )
AND EXISTS ( SELECT '1' /* client has a child < 20 years */
FROM theTABLE lt20
AND year(current date - lt20.DOB) < 20 )

so, extracting each row that satisfied the search criteria.

Hmm... that muddles as well. Should the query return all client rows for which exists at least one child over 20 and at least one child under 20, or only return the rows of those same clients but for which the child's age is not equal to 20? If the latter, then add another ANDed predicate: AND year(current date - orig.DOB) <> 20

Regards, Chuck

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].