Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to creat view from two table having different rows with same ID


Edit (from "Solution 2"):

the tables are
Diagnosis(id,fees,ddate,doct)
Analysis(id,afees,ano,aname,adate)


Edit (from "Solution 3"):

diagnosis values are(1,100,21-6,ali)
Analysis values are(1,50,23,cbc,21-6)
Second row analysis values are(1,70,33,urea,21-6)
The view is
Create view v_accont as(selecy d.id,d.fees,d.ddate,d.doct,a.aname,a.afees from diagnosis d inner join analysis a on d.id=a.id)
I'm getting
Id fees ddate doct aname afees
1 100 21-6 ali cbc 50
1 100 21-6 ali urea 70
I hope this is cleat
Posted
Updated 23-Jun-14 9:24am
v2
Comments
ABAKh 23-Jun-14 4:42am    
i created the view but i got duplicate coulmn fields
Blutfaust 23-Jun-14 15:42pm    
Please do not post your additions to your questions as "Solution". Instead please edit your original question and insert the additional information there.

use SQL join and create view
SQL
CREATE VIEW view_Order AS
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
 
Share this answer
 
Comments
ABAKh 23-Jun-14 4:58am    
i appreciate yotr answer but i still getting duplicate fields
DamithSL 23-Jun-14 6:37am    
can you update the question with your table structures, View creation script you tried and the details of duplicate fields?
CHill60 24-Jun-14 7:05am    
I can't see how DamithSL's solution would give duplicate columns - did you type it in exactly as given in the solution. And do you actually mean duplicate columns or are you getting duplicate rows? Post a couple of lines of your results (use the Improve question link) so we can see what you mean
for sure you will be given two rows because 'id' column for the two rows of analysis table have the same value. To make it work you have to change the value of second row to (2,70,33,urea,21-6)
 
Share this answer
 
Comments
ABAKh 23-Jun-14 17:16pm    
I can't change the value of the second row to 2 , because the two rows in the analysis table are rlated to the row in the diagnosis table which has id=1

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