Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello i have 4 differenct table from which i am retriving the value different value by using foreign key. but problem is that because of foreign key data is comming in duplicate mean it is coming same data.

What I have tried:

i have also try distinct keyword for avoiding duplicate value but it is not work for me
query is

select users.Name,users.UserID,users.Contact,users.photos,pay.PaymentID,pay.Payble,pay.Discount,pay.Total_paid,pay.Balance_Remain,pay.Payment_Mode,pay.Payment_Type,pay.Payment_Describtion,pack.PackageID,pack.Package_Name,pack.Package_Duration,pack.Package_Amount,sub.SubscriptionID,sub.Package_Expire_Date,sub.Package_StartDate from tblUser as users
inner join tblPayment as pay
on users.UserID=pay.UserId
inner join tblPackages as pack
on pack.PackageID=pay.PackageId
inner join tblSubscription as sub
on users.UserID=sub.UID
Posted
Updated 3-Oct-16 19:30pm
Comments
David_Wimbley 3-Oct-16 13:25pm    
You need to post the schema and some sample data. You post this query as if we have access to your database and can run this ourselves. The only thing any of us can do right now is guess at what your issue is which is just a waste of our time and yours.

Help yourself by providing a clear explanation of your issue and the ability for us to replicate your issue. If someone feels like reverse engineering your query for schema we still need some sample data.

Your going to have duplicate data in a join if you've got multiple items with the same key. If that isn't what you want you either need to rethink what you are querying or rethink your schema.

Typically in join the data from the joined tables is duplicated but in such way that the same combination is present only once (depending on the join type). What comes to query execution this is by design but however, the overall result is affected by the data you have in the tables.

One good way to understand the joins is having a look at Visual Representation of SQL Joins[^]
 
Share this answer
 
Hello

if you have duplicated data in your table, it is better to divide it into 2 tables. This is called database normalization. a useful tutorial is :
StudytoNight.

for example if you have FieldName : City duplicated for 1000 person, you would better to divide the table

best regards
 
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