last day (15 days later) » 

9:06 AM
1
A: Finding common values in step_1 and step_2 when values in step_1 is null we need to fetch the values in step_2 in BigQuery

Sayan BhattacharyaYou are using intersect which will fetch only those rows which are available in both the queries. In your first case that is not happening at all thus you are not getting any result. Since you only need to find the common values you can merger the both results and then fetch the distinct not null...

 
Thanks @Sayan Bhattacharya. We need to fetch common values from both query. if in step_a all values are null i need to fetch only step_b. for example_1 Step_a = 1,2,3 and step_b 1,2 we need 1,2. for example_2 Step_a = null,null and step_b 1,2, we need 1,2
for example_1 Step_a = 1,2,3 and step_b 1,2 Result from above query 1,2,3 we need 1,2 example_2 Step_a = null,null and step_b =1,2, we need 1,2 We have two scenario
 
@hepzi What if Step_a = 1,null and step_b =1,2 then ? I mean is in step_a all the values will have null ?
 
for Step_a = 1,null and step_b =1,2 we need 1 as result. In case step_a = null,null step_b= 1,2 we need 1,2
 
@hepzi I have updated my answer let me know if this helps.
 
Great work. Thanks for marvelous support. Keep doing great work @Sayan Bhattacharya
 
9:06 AM
Mention not ,for my answer I just added a where clause to nullify step_b in case step_a has values but there are also other ways to achieve the same . You can check out this thread to improve your query. stackoverflow.com/questions/70286207/….
 
Hi @Sayan Bhattacharya if step_a= 1,2 and step_b = 5 We should not get any values. But above query return step_a results
 
@hepzi So its a third type of case right ?
 
yes @Sayan Bhattacharya
 
@hepzi What if step_a= 1,2 and step_b = 5,null ?
 
we should not get any values @Sayan Bhattacharya
 
9:06 AM
If I give you an answer using Temp table instead of CTE will that be any good ?
Hi hepzi
Can you answer my previous question
 
yes it will work sayan
 
Ok Great
 
9:22 AM
Hi are you there ?
 
yes
 
case 1: a= 1,2,3 b= 1,2 output=1,2
 
yes
 
case 3 a= 1,2 b= 1,2 output=none ?
case 3 a= 1,2 b= 5 output=none ?
how do you differe both this
 
case 3 a= 1,2 b= 1,2 output=1,2
Case 3 a= 1,2 b= 5 output=none
No idea
will come in few min
 
9:25 AM
ok
 
9:49 AM
I am updating the whole answer
Also deleted previous comments for sake of clarity
@hepzi Please check
 
sure
 
10:23 AM
Hi @SayanBhattacharya
we have one more scenario
case4 a= 5, b=null output = none
case 3 a= 1,2 b= 1,2 output=1,2
Case 2 a= 1,2 b= 5 output=none
case 1 a=null, b=1,2 output = 1,2
case4 a= 5, b=null output = none - this not handle
 
Actualy I thought you will need a if there is no b
 
:(
 
Its just we need to tweak if else condition nothing else
can you try this
if row_count_a = 0 then
select distinct * from step_b where customer_id is not null; # case 1 a=null,null b=1,2 output=1,2
else if row_count_b > 0 then # case 3 a=1,2 b=5 output=none , a=1,2,3 b=1,2 output=1,2
select distinct * from (
(select customer_id from step_a where customer_id is not null)
intersect distinct
(select customer_id from step_b where customer_id is not null));
end if;
end if;
 
sure
 
10:38 AM
Thanks a lot @SayanBhattacharya
 
It worked ?
 
10:49 AM
yes
 
Ok then can you add all the cases in your question also
And delete unnecessary comments , After that I will delete this chat
 
ok Thanks
 

last day (15 days later) »