Home > Enterprise >  Join tables having multiple values in a cell
Join tables having multiple values in a cell

Time:09-16

This question was asked to me in an interview. I have two tables as given below

Table1 : [table1] 1

Table2 : [table2] 2

I want the following table as my output. Please tell me the SQL query which can be used to join the two tables and get the output as given below.

Expected Output : [output]3

Sorry for adding the images as I could not figure out how to add the tables

CodePudding user response:

One solution that should work in the majority of databases just uses like to match on the strings.

Also note the sample data is incorrect for B - Orange does not appear in the results.

select t1.name, t2.fruit, t2.value
from t1 join t2 on t1.fruits like Concat('%',t2.fruit,'%')
  • Related