是否可以将左外部普通表与临时表连接起来? [英] Is it possible to Left outer join normal table with temp table?

查看:623
本文介绍了是否可以将左外部普通表与临时表连接起来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建SQL Server查询,并具有带有记录的普通表,另一方面,具有带有记录的临时表,并且该表不为空,并且所有字段都没有冲突 加入

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

推荐答案

是否可以加入这两个不同类型的表? (正常和临时)

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.

例如

永久表:

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)
;

临时表:

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)
;

加入两个表:

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

这篇关于是否可以将左外部普通表与临时表连接起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆