2013-05-30 21 views
2

我需要获取结果与两个表的组合。甲骨文加入查询与类似的条款

select template_id 
from templatetbl 
where template_xml like '%889d-5765405edb42%' 

在quering上,我得到了24条记录。

现在我想用我之前得到的模板ID获取另一组记录。

select * 
from sites 
where site_xml like '%templateid%'. 

Templateid是我之前得到的。

我想这样的查询

select * 
from sites 
where site_xml like (select template_id 
        from templatetbl 
        where template_xml like '%889d-5765405edb42%') 

但得到错误的单行子查询返回多行。

请帮到这两个查询

回答

1

结合起来试试这个:

select * 
from sites 
where site_xml like (select '''%'||template_id||'%''' 
        from templatetbl 
        where template_xml like '%889d-5765405edb42%') 
+0

我认为这仍然将有'太多rows'错误,如果子查询匹配的'templatetbl'多行 – Sodved

0

这应该这样做。一个简单的加入,您可以动态构建LIKE字符串。

SELECT S.* 
FROM templatetbl T, sites S 
WHERE T.template_xml LIKE '%889d-5765405edb42%' 
AND S.site_xml  LIKE '%'||TO_CHAR(T.templateid)||'%' 

编辑:虽然有人警告,但这可能不是你想要的。由于1templateid将匹配11011,... 21 ... 100