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?
Is this possible using LIKE or LEFT ? Depends on what type of sql server you're using for the syntax you need. The simple answer is "yes, this is possible".
Different Types of SQL JOINs (INNER) JOIN : Returns records that have matching values in both tables. LEFT (OUTER) JOIN : Returns all records from the left table, and the matched records from the right table. RIGHT (OUTER) JOIN : Returns all records from the right table, and the matched records from the left table.
To join two tables based on a column match without loosing any of the data from the left table, you would use a LEFT OUTER JOIN. Left outer joins are used when you want to get all the values from one table but only the records that match the left table from the right table.
Is there as way to combine the "in" and "like" operators in Oracle SQL? Answer: There is no direct was to combine a like with an IN statement. However Oracle does support several alternative clauses: CONTAINS clause: the contains clause within context indexes.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With