PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 29, 2022

[FIXED] What is alternative to performing a left join on GTE or LTE conditions?

 October 29, 2022     hive, hiveql, join, left-join, non-equi-join     No comments   

Issue

I am required to use a specific old version of HIVE that prevents me from joining 2 tables on GTE or LTE conditions. For example what is the equivalent of

select *
from table1 as t1
left join table2 as t2
on t1.id = t2.id
  and (t1.date >= t2.date and t1.date <= t2.date+7) -- i can no longer do this condition

What is an alternative query to this?


Solution

The alternative is to move GTE/LTE part of condition to the where clause which will be applied after join as a filter:

select *
  from table1 as t1
       left join table2 as t2 on t1.id = t2.id
 where (t1.date >= t2.date and t1.date <= date_add(t2.date,7)) 
       or t2.id is null


Answered By - leftjoin
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing