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 <bdis...@dissensoftware.com> http://www.dissensoftware.com Director, Dissen Software, Bar & Grill - Israel ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN