SQL Server join on whichever column has value populated -


i have 2 tables each following id columns:

ticker sedol, isin 

each row has 1 or more of these columns populated value. join on whichever column has value. know how join way? thanks.

ticker, sedol , isin different formats assume need

select *   t1        join t2          on t1.ticker = t2.ticker              or t1.sedol = t2.sedol              or t1.isin = t2.isin  

performance poor if tables large however, see is having 'or' in inner join condition bad idea?.

if both tables consistent on columns supplied particular security potentially faster can use hash or merge join not nested loops.

select *   t1        inner join t2          on exists (select t1.ticker,                            t1.sedol,                            t1.isin                     intersect                     select t2.ticker,                            t2.sedol,                            t2.isin)  

or if tables not consistent option might be

select *   t1        inner join t2          on t1.ticker = t2.ticker union select *   t1        inner join t2          on t1.sedol = t2.sedol union select *   t1        inner join t2          on t1.isin = t2.isin  

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -