如何从连接创建新表

时间:2016-07-13 23:39:30

标签: sql join

我需要将以下连接放入SQL表中:

SELECT *
FROM [Disbursements_Master_Vendor_Tbl]
    LEFT JOIN [Disbursements_Bravo_Vendor_Master_Tbl]
        ON [Disbursements_Master_Vendor_Tbl].Vendor = [Disbursements_Bravo_Vendor_Master_Tbl].Username
WHERE [Disbursements_Master_Vendor_Tbl].Vendor IS NULL OR [Disbursements_Bravo_Vendor_Master_Tbl].Username IS NULL

我该怎么做?

1 个答案:

答案 0 :(得分:0)

假设您已使用字段定义了表,则打算使用create table语句将数据插入到表中。

INSERT INTO Table_Name (column value1, column value2, etc..)

SELECT * FROM [Disbursements_Master_Vendor_Tbl] LEFT JOIN
Disbursements_Bravo_Vendor_Master_Tbl] ON
[Disbursements_Master_Vendor_Tbl].Vendor
[Disbursements_Bravo_Vendor_Master_Tbl].Username WHERE
[Disbursements_Master_Vendor_Tbl].Vendor IS NULL OR
[Disbursements_Bravo_Vendor_Master_Tbl].Username IS NULL

OR:

使用SELECT INTO语句(仅在尚未创建表时):

SELECT * INTO TableName 
FROM [Disbursements_Master_Vendor_Tbl] LEFT JOIN
Disbursements_Bravo_Vendor_Master_Tbl] ON
[Disbursements_Master_Vendor_Tbl].Vendor
[Disbursements_Bravo_Vendor_Master_Tbl].Username WHERE
[Disbursements_Master_Vendor_Tbl].Vendor IS NULL OR
[Disbursements_Bravo_Vendor_Master_Tbl].Username IS NULL