Not exactly, as I left out that there is also column D and E which may have
different values.

>From your comment it would appear that this is a lot more difficult..

On Tue, 19 Apr 2022 00:13:00 +0200 Bernd Oppolzer <[email protected]>
wrote:

:>If the results in col1, col2 and col3 may be different for the same 
:>"something" condition
:>in tables table1 thru table3, my solution is not correct.
:>
:>In this case, you need some sort of "select from table1 ... union all ...
:>select from table2 where not exists (result from table1)" etc. etc.
:>
:>But this is a complete other requirement. You should maybe be more 
:>specific about
:>what your targets are.
:>
:>Kind regards
:>
:>Bernd
:>
:>
:>Am 19.04.2022 um 00:02 schrieb Bernd Oppolzer:
:>> select col1, col2, col3, min (wherefound)
:>>   from (select col1, col2, col3, 'source 1' as wherefound
:>>           from table1
:>>          where something
:>>       union ALL
:>>         select col1, col2, col3, 'source 2' as wherefound
:>>           from table2
:>>          where something
:>>       union ALL
:>>         select col1, col2, col3, 'source 3'  as wherefound
:>>           from table3
:>>          where something) as t1
:>>  group by col1, col2, col3
:>>
:>> I changed the UNION to UNION ALL, BTW;
:>>
:>> kind regards
:>>
:>> Bernd
:>>
:>>
:>> Am 18.04.2022 um 19:48 schrieb Binyamin Dissen:
:>>> Seems that I have been knocked off of the DB2-L listserv.
:>>>
:>>> I am doing a union of three queries where it is possible that the 
:>>> critical
:>>> columns are in more than one of the queries.
:>>>
:>>> For example:
:>>>
:>>>                   select col1, col2 col3, 'source 1'
:>>>                            from table1
:>>>                            where something
:>>>                   union
:>>>                   select col1, col2, col3,, 'source 2'
:>>>                             from table2
:>>>                            where something
:>>>                   union
:>>>                   select col1, col2, col3, 'source 3'
:>>>                              from table3
:>>>                              where something
:>>>
:>>> I would like a single row even if the data (col1, col2, col3) is in 
:>>> more than
:>>> one of the queries, so that 'source1' is returned if in table1 and 
:>>> table2
:>>> and/or table3, 'source 2' if not in table1 but in table2 (and perhaps 
:>>> table3)
:>>> and 'source 3' if only in table 3.
:>>>
:>>> -- 
:>>> Binyamin Dissen <[email protected]>
:>>> http://www.dissensoftware.com
:>>>
:>>> Director, Dissen Software, Bar & Grill - Israel
:>>>
:>>> ----------------------------------------------------------------------
:>>> For IBM-MAIN subscribe / signoff / archive access instructions,
:>>> send email to [email protected] with the message: INFO IBM-MAIN
:>>
:>> ----------------------------------------------------------------------
:>> For IBM-MAIN subscribe / signoff / archive access instructions,
:>> send email to [email protected] with the message: INFO IBM-MAIN
:>
:>----------------------------------------------------------------------
:>For IBM-MAIN subscribe / signoff / archive access instructions,
:>send email to [email protected] with the message: INFO IBM-MAIN

--
Binyamin Dissen <[email protected]>
http://www.dissensoftware.com

Director, Dissen Software, Bar & Grill - Israel

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to