1

I have two tables

first table

Row  feature_groups           array_words   
1    chat seller              chat
2    product picture/video    product picture
                              video

second table

Row  events                                       
1    product picture is perfect     
2    video on product babyboy
3    chat bot creation
4    image gorilla

I want to filter out the events on the basis of array_words

Result should be -

Row  events                         feature_groups
1    product picture is perfect     product picture/video
2    video on product babyboy       product picture/video
3    chat bot creation              chat seller

Any help with biqquery can be of great help

2
  • how do you pretend to join both tables? do you have any ID that matches both? Commented Sep 16, 2021 at 8:34
  • I can do cross join, no matching id column Commented Sep 16, 2021 at 8:57

1 Answer 1

3

Consider below approach

select events, feature_groups from (
  select *, 
    (
      select count(1)
      from unnest(split(t2.events, ' ')) word
      join t1.array_words word
      using(word)
    ) match
  from table_2 t2, table_1 t1
  where true
  qualify row_number() over(partition by events order by match desc) = 1
  and match > 0
)     

if applied to sample data in your question

Table_1
enter image description here

and Table_2
enter image description here

output is

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

thanks , that solves it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.