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

mod rewrite - Using "?" when rewriting the URL -

.htaccess: Transfer name to index.php if not directory public -

Admob integration with pygame in android -