title: How to reference a column's query value vs stored value?
body: <p>I apologize for the title, I couldn't find a good way to word my question. I'm very new to SQL.</p>
  
  <p>Essentially, I'm creating this table (the ids actually reference the students table, but I've simplified it here):</p>
  
  <pre><code>CREATE TABLE followers (student_id        int not null,
                          followee_id       int not null,
                          followsback       boolean,
                          PRIMARY KEY(student_id, followee_id)
                          SET followsback = IF(SELECT from followers
                            WHERE student_id = followee_id AND 
                            followee_id = student_id, 1, 0)
  </code></pre>
  
  <p>My problem lies with the IF statement. Say I ran this INSERT query:</p>
  
  <pre><code>INSERT into followers(student_id, followee_id) values(001,002)
  </code></pre>
  
  <p>This is supposed to store that student 001 is following student 002.</p>
  
  <p>I need to select the followee (002) and check if they are following the student (001) back. To do this, I need to check the followers table for a user with student_id = followee_id (e.g student_id = 002), then check to see if that user (002) is following the original student_id (001).</p>
  
  <p>The problem is that I don't know how to reference the student_id as specified within the INSERT query vs referencing the value within my SELECT query.</p>
  
  <p>Then if the two students are following each other then I need to set followsback to 1.</p>
  
  <p>Hopefully this makes sense, I am having a ridiculously hard time explaining this.</p>