Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me to compare two fields from two different tables.
I have 2 tables:
1) Prescribed_Medicines(PID(PK),medCode(FK), UnitPrice, Quantity) and
2) NHIS_Medicines(medcode(PK), UnitPrice, Quantity)

I want to compare the fields UnitPrice, and Quantity in Prescribed_Medicines table with
fields UnitPrice and Quantity in NHIS_Medicines table

Please i need help, please help me
Posted
Comments
ZurdoDev 19-Mar-12 8:21am    
Compare and do what? Find differences? Find matches? Find sum, avgs, etc?
shreekar 28-Mar-12 17:18pm    
If you think there is a correct answer provided, please mark the answer.

1 solution

If you have medCode in both tables, where is the problem?
The example below shows how to get records from 2 tables with equal medCodes and UnitPrices.
SQL
SELECT PM.medCode AS PM_medCode, PM.UnitPrice AS PM_UnitPrice, PM.Quantity AS PM_Quantity, NM.medcode AS NM_medcode, NM.UnitPrice AS NM_UnitPrice, NM.Quantity AS NM_Quantity
FROM Prescribed_Medicines AS PM INNER JOIN NHIS_Medicines AS NM ON PM.mdeCode = NM.medCode
ORDER BY PM.medCode
WHERE PM.UnitPrice = NM.UnitPrice
 
Share this answer
 
v2

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