Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
favorite
I have Three Tables In Database

Table : Group

Id, Name
Table : doctor

Id ,DId, DoctorName,
Table : Ratio

Id , UpLimit , downLimit.
When i inner join them , I am Getting duplicate Values to Uplimit and downlimit,,

Actually Group is related to doctors, One group id can have multple doctors,, so when i save some data with Group and doctor, it is saving to all the records with same data, uplimit downlimit varies with different doctors , but when i inner join dem its showing same to all doctors,, how to skip uplimit and downlimit how to write the Query..

Select A.Group , B.doctor , C.Uplimit, D.downlimit from Group A
inner join Doctor B
on A.id = B.id
inner join ratio c
on A.id = c.id
issue is When i separately check it with doctor id in doctor table it is showing only one record, when i inner join them its showing same data to all doctors to particular how to join them??

What I have tried:

Select A.Group , B.doctor , C.Uplimit, D.downlimit from Group A
inner join Doctor B
on A.id = B.id
inner join ratio c
on A.id = c.id
Posted
Updated 4-Mar-17 4:37am
Comments
Peter Leow 4-Mar-17 6:41am    
You said "uplimit downlimit varies with different doctors", it seems to infer that the Id field of the ratio table is related to the Did field of the doctor table, Is that correct?
Mahesh2223 4-Mar-17 7:17am    
No , id is common to all three tables,, and doctor column has did , and ratio has did so i made a mistake there so i got the issue now
Peter Leow 4-Mar-17 10:38am    
It is strange that all three tables share the same id. You should re-examine your database design.
Mahesh2223 4-Mar-17 7:20am    
this is a stored procedure, this gives values to grid view, i have a small issue in dis as well, if i select the above query that means 'all' i should get all records starting with group in grid, and another if has not selecting 'all' my grid should start from doctor, how to skip a column in grid, depending on drop down selection

1 solution

Based on your feedback, it appears that you are not certain about your database design. For example, what is the purpose of the ratio table? If every doctor has his own uplimit and downlimit, they can simply be included in the doctor table, then there is no need for the ratio table. Suggest you re-look into your database design with reference to user requirements. Some references to help:
1. Introduction to database design[^]
2. 1NF, 2NF, 3NF and BCNF in Database Normalization[^]
Only after the database design issues are ironed out, should you proceed with coding.
 
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