soheil bijavar
soheil bijavar

Reputation: 1213

Is it possible to Left outer join normal table with temp table?

I create SQL server query and have normal table with records and in the other hand have a temp table with record and this table not empty and all fields doesn't have any conflict to join

is possible to join this two different type table?

SELECT NormalTable.Entityname  FROM NormalTable LEFT JOIN 
       #Temp tmp ON tmp.joinID = NormalTable.joinID

Upvotes: 5

Views: 83327

Answers (1)

Himanshu
Himanshu

Reputation: 32612

is possible to join this two different type table? (normal and temporary)

Yes it is possible to join different type of table (permanent and temporary tables). There is no different syntax to join these tables.

E.g.

Permanent table:

CREATE TABLE NormalTable
    ([plateno] varchar(1), [JoinID] int)
;

INSERT INTO NormalTable
    ([plateno], [JoinID])
VALUES
    ('A', 1),
    ('B', 2),
    ('C', 2),
    ('A', 3),
    ('B', 2),
    ('A', 4),
    ('A', 1)
;

Temporary table:

CREATE TABLE #Temp
    ([id] int, [date] date, [score] int)
;

INSERT INTO #Temp
    ([id], [date], [score])
VALUES
    (1, '2013-04-13', 100),
    (2, '2013-04-14', 92),
    (3, '2013-04-15', 33)
;

Join both tables:

SELECT N.* FROM NormalTable N
LEFT JOIN #Temp T ON N.JoinID = T.ID

Have a look at this SQLFiddle

Upvotes: 6

Related Questions