SQLTeam.com | Weblogs | Forums

Copy data from 2 tables in another table


#1

hey guys, you were very helpful teh last time i reached out to you and maybe you acn help me this time also.
I know it must be very simple but at this moment im stuck.
i have 2 tables:table A and table B. i need to populate the final table with data from table A based on table B.
image

i need to copy the rows from table A with the condition that the ID='default' for both tables
and column count =1 from table B.

final table is a temporary table for me

this si what i have so far and it doesnt work:

select t1 ID,
t1 Org ID into #final table
from table A inner join table B
where t2 ID='default' and t2 Count=1

it gives me an error: Incorrect syntax near the keyword 'where'


#2

change "where" to "on"


#3

so i wrote
select t1.[ID], t1.[Org ID]into #temp
from [dbo].[table A] as t1 inner join [dbo].[table B]as t2
on t2.[ID]='default' and t2.[count]=1

and the final result is:

image

but i only wanted to have those 2 raws that i mentioned in teh final table. I thought that inner joint takes only the common data from both tables not all the data :frowning:


#4
select t1.[ID]
      ,t1.[Org ID]
  into #temp
  from [dbo].[table A] as t1
       inner join [dbo].[table B] as t2
               on t2.[ID]=t1.[ID]
              and t2.[Org ID]=t1.[Org ID]
              and t2.[ID]=‘default’
              and t2.[count]=1
;