Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to compare two field of two separate table !
for example tbl_User (UserId, amount) and tbl_Product(UserId,ProductId, Pamount) ...
and for example comparing fields: amount and Pamount
is there a need to have a relation in this two table ??
please help me ...
Posted
Comments
Amir Mahfoozi 7-Feb-12 1:45am    
What have you done so far? Please provide your SQL statement.

No.
For example there is no formal relationship between these two tables:
SQL
SELECT S.[StudentId], S.Name, M.Amount , M.MissionID
  FROM [Testing].[dbo].[Student] AS S, [Testing].[dbo].[myTable] AS M
  WHERE S.StudentId=M.MissionID
 
Share this answer
 
Comments
EhsanGhanbari 6-Feb-12 14:23pm    
is it possible to compare two field of table that are in same data type ??
I wanna to compare two amount of money that area stored in two joined separate table ?? please help me about that ...
OriginalGriff 6-Feb-12 14:44pm    
The query I showed you does just that, but with integers - there is no join, no formal relationship needed. As long as the two fields are the same datatype, the comparison is valid.
Doesn't mean it will be efficient! :laugh:
Hi,

it's all depends upon what you would like to compare ? suppose you would like to find out sum of (Pamount+amount) for every user in that case you need aggregate function and joining between UserId of the both the field.(this is just an example)

Conclusion : you do not need joining only if tbl_Product.Pamount and tbl_User.amount is independent on UserId.

hope this information will help you,

thanks
-Amit.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900