Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

select rows from an unNormalized table based on data from a Normalized table

$
0
0

Is there a join type I could use or something else to select rows from an unNormalized table based on the data from a Normalized table? Here are the 2 tables.  I want to select the rows from #tmp1 where in_out column values in #tmp2 are the same for each of the columns in each row of #tmp1

create

table #tmp1(rowID intidentity(1,1), cur varchar(10), prev varchar(10))

insert into #tmp1 select 'sam', 'tam' union all select 'pam', 'zam' union all select 'kam', 'ram' union all select 'mam', 'bam' create table #tmp2(title varchar(10), in_out varchar(10)) insert into #tmp2 select 'sam', 'in' union all select 'tam', 'in' union all select 'pam', 'in' union all select 'zam', 'out' union all select 'kam', 'out' union all select 'ram', 'out' union all select 'mam', 'out' union all select 'bam', 'in'

my result set from #tmp1 then would be these rows:

#tmp1

cur     prev       in_out
sam     tam        in       --both columns in #tmp1 have same in_out in #tmp2
kam     ram        out

--what is the Tsql to accomplish this?

Thanks


Rich P




Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>