Question

I have this query:

SELECT *
FROM Parent.Table
WHERE Ref_Num IN ('4205' or (SELECT Ref_Num FROM Child.Table WHERE Ref_Num ='234'))
AND Asset_Type IN ('PUMPS','COLL')

This query doesn't work. The subquery returns 53 rows, instead of typing out all the children ref numbers is there a way to put them in the query along with the parent number of '4205'.

Thanks.

Was it helpful?

Solution

Perhaps you could try something like

SELECT *
  FROM Parent.Table
  WHERE Ref_Num In (SELECT Ref_Num
                      FROM Child.Table
                      WHERE Ref_Num ='234'
                    UNION
                      SELECT '4205' As Ref_Num
                        FROM SYSIBM.SYSDUMMY1)
    AND Asset_Type IN ('PUMPS','COLL')

Note that SYSDUMMY1 is an EBCDIC table. If you need ASCII, use SYSDUMMYA. If you need Unicode, use SYSDUMMYU.

Share and enjoy.

OTHER TIPS

Yes, use a union query

 select 4205 ref_num
 from some_small_table
 union
 select ref_num
 from child.table
 etc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top