문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

Yes, use a union query

 select 4205 ref_num
 from some_small_table
 union
 select ref_num
 from child.table
 etc
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top