5
Answers

I fall in mistake Please help me my code not work correct

Photo of nofact noface

nofact noface

9y
584
1

Hello every one

I fall in mistake

Please help me

I have 3 table

1 – User (id, email)

2 – Friend (sender, receiver, state)

3 – Post (sender, text, date)

Now

I want to select User (id), Post (*)

But

Select user’s post who is login and the other guy that receive a request for follow from the user and my code is:

Create PROCEDURE showpost

@email nvarchar (50)

AS

BEGIN

Select User.Code as code, post.* from post, friend, User where (User.email=post.sender) and ((friend.sender=@email or friend.reciver=@email) and state='ok' and (post.sender=friend.sender or post.sender=friend.reciver)) order by post.code desc

END

This is a problem

When show post the user’s post will be Repeated as many as his request for follow

Attached file is better

http://s6.uplod.ir/i/00629/4m2dkharb1oe.png
 

Answers (5)

1
Photo of Pankaj  Kumar Choudhary
NA 29.8k 3.1m 9y
Hello @Nofact  you can use distinct keyword for your query like as
 
 

Select DISTINCT User.Code as code, post.* from post, friend, User where (User.email=post.sender) and ((friend.sender=@email or friend.reciver=@email) and state='ok' and (post.sender=friend.sender or post.sender=friend.reciver)) order by post.code desc

 i also try this method for your tables and  found correct o/p
 
Result Without Distinct Keyword
 
After Distinct Keyword
 
 
Please tell me if this solution is not as you required . I will try again.
Accepted
0
Photo of nofact noface
NA 15 991 9y
thank you thank you thank you alot
0
Photo of nofact noface
NA 15 991 9y
http://s6.uplod.ir/i/00629/br1930c8nskx.png another pic from relation
0
Photo of Pankaj  Kumar Choudhary
NA 29.8k 3.1m 9y
hello @Nofact  it is difficult to understand your table structure can you post relationship of your tables
 
0
Photo of Bhushan Bhasme
NA 948 135k 9y
I think You need To go by applying inner join on one by one table