title: using sql distinct to retrieve same column from two different database tables
body: <p>I have a question, and I can't seem to find any lead on this. I am looking to retrieve the same column from two tables in the database, e.g. User and UserGroup. </p>
  
  <p>If I were to select John from the User Table, John will be displayed in the UserGroup Table, and in the User Table, John will no longer be displayed. Is it possible to even do a query like that??</p>
  
  <pre><code>User
   1. John
   2. Jane
   3. Tom
  
  User Group
   Empty
  </code></pre>
  
  <p>After selection of John:</p>
  
  <pre><code>User
   2. Jane
   3. Tom
  
  User Group
   1. John
  </code></pre>
  
  <p>Instead of having the following (which I have now):</p>
  
  <pre><code>User
  
   1. John
   2. Jane
   3. Tom
  </code></pre>
  
  <p>After Selection of John:</p>
  
  <pre><code>UserGroup
  
   1. John
  </code></pre>
  
  <p>The only possible way I can think of right now is the following:</p>
  
  <pre><code>SELECT DISTINCT usuarios.id_usuario
  FROM usuarios
  JOIN 
  usuarios_grupos
  ON
  (usuarios_grupos.id_usuario = usuarios.id_usuario)
  </code></pre>
  
  <p>However, I ran the query, and it doesn't give me the ideal result. Any thoughts on this??</p>
  
  <p>I did UNION ALL:</p>
  
  <pre><code>SELECT DISTINCT usuarios.id_usuario
  FROM usuarios
  UNION ALL
  SELECT DISTINCT usuarios_grupos.id_usuario
  FROM usuarios_grupos
  </code></pre>
  
  <p>and I got the following result:</p>
  
  <pre><code> 1. John 
   2. Jane
   3. Tom
   4. John
   5. Jane
   6. Tom
  </code></pre>