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:
SELECT *
FROM theTABLE orig
WHERE EXISTS ( SELECT '1' /* client has a child > 20 years */
FROM theTABLE gt20
WHERE orig.CLIENT = gt20.CLIENT
AND year(current date - gt20.DOB) > 20 )
AND EXISTS ( SELECT '1' /* client has a child < 20 years */
FROM theTABLE lt20
WHERE orig.CLIENT = lt20.CLIENT
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
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 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].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.