You can do inner join like this
SELECT
LocID, ScheduledCompletion,LocID1, ScheduledCompletion1
FROM table1 t1 inner join table2 t2 on t1.LocID = t2.LocID1
But the above query will return 16 Rows, since the
table1 contains 4 rows with LocID as 100 and
table2 contains 4 rows with LocID1 as 100
so it will Perform
4*4
operation and
returns 16 Rows
------------------------------------------------------------------------------------------------------------------
TO get the result which u need you can try like this..
declare @table1 table ( LocID int , ScheduledCompletion varchar(33))
declare @table2 table ( LocID1 int , ScheduledCompletion1 varchar(33))
insert into @table1 ( LocID, ScheduledCompletion) values ( 100 , 'aa')
insert into @table1 ( LocID, ScheduledCompletion) values ( 100 , 'bb')
insert into @table1 ( LocID, ScheduledCompletion) values ( 100 , 'cc')
insert into @table1 ( LocID, ScheduledCompletion) values ( 100 , 'dd')
insert into @table2 ( LocID1, ScheduledCompletion1) values ( 100 , 'ee')
insert into @table2 ( LocID1, ScheduledCompletion1) values ( 100 , 'ff')
insert into @table2 ( LocID1, ScheduledCompletion1) values ( 100 , 'gg')
insert into @table2 ( LocID1, ScheduledCompletion1) values ( 100 , 'hh')
;with T1 (RowNum,LocID,ScheduledCompletion) as (
select row_number() over (order by LocID) RowNum, LocID , ScheduledCompletion
from @table1
),
T2 (RowNum,LocID1,ScheduledCompletion1)as (
select row_number() over (order by LocID1) RowNum, LocID1 , ScheduledCompletion1
from @table2
)
select a.LocID, a.ScheduledCompletion , b.LocID1 , b.ScheduledCompletion1
from T1 a
inner join T2 b on a.RowNum = b.RowNum