Note that there are some explanatory texts on larger screens.

plurals
  1. POselect statement + join n' stuff
    primarykey
    data
    text
    <pre><code>SELECT * FROM LiveStreams l INNER JOIN Friendships f ON f.Sender = l.Sender OR f.Sender = l.Recipient OR f.Recipient = l.Sender OR f.Recipient = l.Recipient WHERE l.Sender = @SomeUser OR l.Recipient = @SomeUser </code></pre> <p>My attempt for now ^</p> <p>So, what im trying to do here is get all the streams from (livestreams table) of all the friends of a given @SomeUser. We can know the friends by using this query:</p> <pre><code>SELECT Id, CASE WHEN Sender = @UserName THEN Recipient ELSE Sender END AS Friend, IsPending, DateTime FROM Friendships WHERE (Sender = @UserName OR Recipient = @UserName) AND IsPending = @IsPending; </code></pre> <p>Given a @SomeUser, I would like to lookup his/her friends from the Friendships table having 3 columns (Id, Sender, Recipient) using single row (where the friend can be either the sender or the recipient) I would like to get all the friends and then get their speicifed stream from the livestream table (Id, Value, Sender, Recipient) </p> <p>Sort of like the Facebook NewsFeed, When a @Person goes to the livestream pages, we will look for all the streams coming from his friends only. If his friends INITITED the stream or were sent the stream so they could be on either column too.. Sender or Recipient.</p> <p>How can this be achieved? Ty</p> <p>How can I do that?</p> <p>**</p> <h2>UPDATE:</h2> <p>**</p> <p>THanks for the answers.</p> <pre><code>SELECT l.* LiveStreams l INNER JOIN Friendships f ON f.Sender = 'beta' OR f.Recipient = 'beta' WHERE l.Sender = 'beta' OR l.Recipient = 'beta' OR l.Sender = f.Recipient OR l.Sender = f.Sender OR l.Recipient = f.Sender OR l.Recipient = f.Recipient </code></pre> <p>What doesn't work about this is that it still shows the feeds where beta is either the stream sender or the reciever, which I don't want because he's not a friend of himself. is there a fix? Thanks again.</p> <p>I don't know if this helps but that's how im getting the friend list of someone..</p> <pre><code> "SELECT foo.* " + "FROM (SELECT Id, Sender, CASE " + "WHEN Sender = @UserName THEN Recipient " + "ELSE Sender " + "END AS UserName, IsPending, DateTime " + "FROM Friendships WHERE " + "Sender = @UserName " + "or Recipient = @UserName " + ") as foo " + "where foo.UserName = @FriendName;"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload