Ah, thank you! I got to the point where I thought I was pretty comfortable with SQL, but clearly I've been away longer than I realized.
--- Bob Bridges, [email protected], cell 336 382-7313 /* Error saving file. Format drive now (Y/y)? */ -----Original Message----- From: IBM Mainframe Discussion List <[email protected]> On Behalf Of Bernd Oppolzer Sent: Monday, April 18, 2022 18:03 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; --- 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. ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN
