简体   繁体   English

如何使用SQL比较两个不同数据库中两个不同列之间的数据

[英]How to compare data between two different columns in two different databases with SQL

Hello I am new to SQL server and I have two databases with two different tables, they are on the same server and I am using Microsoft SQL Server management studio. 您好我是SQL Server的新手,我有两个带有两个不同表的数据库,它们位于同一服务器上,并且我正在使用Microsoft SQL Server Management Studio。 I need to compare two columns and find which entries do not show up in both columns. 我需要比较两列,并找出在两列中均未显示的条目。 Some of these results do match up and I only want to find the differences. 这些结果中有些确实匹配,我只想找到差异。

Databases and fields that need querying: 需要查询的数据库和字段:

database1, ID number database2, complex ID number database1,ID号database2,复杂ID号

I would just like to find out the entries that do not match up between the two using SQL. 我只想使用SQL找出两者之间不匹配的条目。

Thanks for your help! 谢谢你的帮助!

You just need to make sure to reference each piece with the 3 or 4 part name. 您只需要确保使用3或4个零件名称来引用每个零件。

Database.Schema.Table when referencing tables and Database.Schema.Table.Column when referencing columns 引用表时为Database.Schema.Table,引用列时为Database.Schema.Table.Column

You can write joins between databases this way and definitely pull data from more than one database. 您可以通过这种方式在数据库之间编写联接,并且绝对可以从多个数据库中提取数据。

use linked server see this link 使用链接服务器查看此链接

read all, at the end you have the use of sql statements use 阅读全部,最后您已使用sql语句使用

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

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