2

I want to compare two tables with the same columns:

  • product - Id, Name, Description
  • Temp_Product - Id, Name, Description

Now update done by user will be saved into Temp_Product. When admin will see the details of that product I need to show the changes done by user. I want to compare both tables with a query and return columns that have changed from Product to Temp_Product.

Please suggest me better way to do this?

2
  • 1
    Well, in order to suggest a better way - we need to see what you already have! Show us what you have tried yourself Commented Nov 17, 2012 at 8:40
  • Which columns remain the same and which can change? Commented Nov 17, 2012 at 8:40

2 Answers 2

2
Select p.id,p.name as orgn,t.name as altn,p.descripion as orgd,t.description as altd
from product p
join tmp_product t
on t.id=p.id and (t.name<>p.name or t.description <> p.description)
Sign up to request clarification or add additional context in comments.

1 Comment

how can i make a linq query equivalent of this?
1

I want to compare both tables with a query and return columns that have changed from Product to Temp_Product

Since the two tables have the same structure, you can use the EXCEPT set oeprator for this:

SELECT * FROM Temp_Product
EXCEPT
SELECT * FROM Product;

SQL Fiddle Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.