Joining tables with LIKE (SQL)

安稳与你 提交于 2019-12-19 05:37:06

问题


First of all I am using Oracle:

Table One Name = tableone

Table Two Name = tabletwo

tableone has a column named pizzaone, tabletwo has a column named pizzatwo. I want to join tableone to tabletwo where pizzaone is somewhere in the pizzatwo's name.

What I tried:

select * 
from tableone 
   join tabletwo on tableone.pizzaone like ('%' + tabletwo.pizzatwo + '%')

How can I correct this query?


回答1:


Try this syntax instead:

select * 
from tableone 
   join tabletwo on tableone.pizzaone like ('%' || tabletwo.pizzatwo || '%')

Oracle's string concatenation operator is the double pipe (||). The invalid number error is because Oracle expects numeric operands for the '+' operator.



来源:https://stackoverflow.com/questions/5224907/joining-tables-with-like-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!