Reputation: 175
I have two tables A and B. Table A contains field 'number'. Table B contains 'number_start' and 'number_end'. I want to merge these two tables such that final table contains details from both the table where number is between number_start and number_end.
I want to achieve this in redshift /sql. let me know if anyone has some clue.
Upvotes: 0
Views: 5896
Reputation: 683
Use join statement. Try This.
select t1.numbers from t1,t2 where t1.numbers>t2.min and t1.numbers<t2.max;
Upvotes: 1
Reputation: 466
SELECT t1.`number`,t2.`end_number`, t2.`start_number` FROM table1 t1, `table2` t2
WHERE `number` >= start_number
AND number <=end_number
do you want some thing like this? Please check this
Upvotes: 1
Reputation: 322
Perform this Join Operation
Select a.Number,b.EndNumber,b.StartNumber
from A a join B b
on a.Number >= b.StartNumber and a.Number <= b.EndNumber
Upvotes: 2
Reputation: 327
If both table is not related with each other then you can use this query
select CONVERT(varchar, A.number_start) + CONVERT(varchar,B.number) + Convert(varchar,A.number_end) from A cross join B
Or If this table has foreign key,then you can use inner join in this query
Upvotes: 0