开发者

How to compare entire row of a table with entire row of another table

Is there a way in SQL Server to compare entire row of one table with another table which has same data types.

Example开发者_Python百科:

CREATE TABLE [DBO].[PRODUCT]
  (
     [PID]  [INT] NULL,
     [NAME] [NCHAR](10) NULL,
     [PDID] [INT] NULL
  )

select * from product p, product c where p.{entirerow} = c.{entirerow}

is there some kind of option here?


Use SQL INTERSECT(all matching rows) and EXCEPT (all different rows), here for example:

SELECT * FROM Table1 INTERSECT SELECT * FROM Table2
SELECT * FROM Table1 EXCEPT SELECT * FROM Table2

You can compare subsets of columns by replacing * with a column list or subsets of rows by using a WHERE clause.

One caveat is that the schema's of the tables need to be the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜