简体   繁体   English

来自2个不同数据库的2个SQL查询,创建1个表合并列

[英]2 SQL Queries from 2 Different Databases, Create 1 Table merging Columns

Suppose that I have two queries from two databases as below. 假设我有来自两个数据库的两个查询,如下所示。

LIST 1 from [Alphabet] table [字母]表中的清单1

  • ABCD A B C D

    1. A 一种
    2. B
    3. C C
    4. D d

LIST 2 from [Integers] table [Integers]表中的LIST 2

  • Numbers 号码

    1. 101 101
    2. 201 201
    3. 301 301
    4. 401 401

I would like to merge them so that in Excel sheet, I want to see that alphabet table is in columns A and integers table is in column B. 我想合并它们,以便在Excel工作表中,我想看到字母表在A列中,而整数表在B列中。

Here my suggestion: 这是我的建议:

Create Table merged ( Select [ABCD] from [Alphabet] join with [Numbers]  from [Integers])

How can I improve the quality to work? 如何提高工作质量?

And should the row numbers be equal in both tables? 并且两个表中的行号应该相等吗? Say, 27 letters and 27 integers, or would work with 27 letters and integers [1,20]? 说27个字母和27个整数,还是可以使用27个字母和整数[1,20]?

This Is My First Answer and i hope it would help ...Back to your question How can I improve the quality to work? 这是我的第一个答案,希望对您有帮助...返回您的问题如何改善工作质量? You Must use constraints to enforce rules for the data in your tables. 您必须使用约束来强制执行表中数据的规则。 You need two columns of the same type, one on each table [Alphabet table] and [Integers table], to JOIN on. 您需要两列相同类型的列(要在每个表[Alphabet表]和[Integers表]上各占一列)进行JOIN。 Whether they're primary and foreign keys or not doesn't matter. 它们是主键还是外键都没有关系。

And should the row numbers be equal in both tables? 并且两个表中的行号应该相等吗? the answer is No Depending on what joins you will Use ! 答案是否定的,取决于您将使用的联接! SQL joins are used to query data from two or more tables, based on a relationship between the corresponding rows in these tables. SQL连接用于根据这些表中相应行之间的关系从两个或多个表中查询数据。 • INNER JOIN: Returns all corresponding rows from multiple tables. •INNER JOIN:从多个表返回所有对应的行。 • LEFT OUTER JOIN: Returns all rows from the left table, corresponding rows in the right table & if there are no matches, returns NULL. •LEFT OUTER JOIN:返回左表中的所有行,右表中的对应行;如果没有匹配项,则返回NULL。 • RIGHT OUTER JOIN: Returns all rows from the right table, corresponding rows in the left table, & if there are no matches, returns NULL. •RIGHT OUTER JOIN:返回右表中的所有行,左表中的对应行;如果没有匹配项,则返回NULL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM