简体   繁体   中英

Merge two tables without common column in sql

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.

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

Use join statement. Try This.

select t1.numbers from t1,t2 where t1.numbers>t2.min and t1.numbers<t2.max;
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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM