title: Postgresql: replace parameter in select if data in LEFT JOIN exists
body: <p>Currently I have two tables as follows:</p>
  <p>Invitation Code: id, code, first_name, last_name, email, used, user_id</p>
  <p>Users: id, first_name, last_name, email</p>
  <p>And what I want to get through SELECT is to
  Get all invitation codes and users; if the invitation code has user_id (which means a user has used it), then display users' first_name, last_name, email rather than what the invitation code has (replace what is selected by condition); and don't display user again if they have been found by invitation code part. Currently, not all invitation codes are used by a user. For now what I have done is to select Invitation Code and User in two different query, but that way doesn't allow me to build paginator, as I won't know how many people I would get from each table in each page and it would be hard to keep them not repeating themselves.</p>
  <p>Any suggestion would be helpful.</p>
  <p>Edit:</p>
  <p>sample data:
  Users</p>
  <pre><code>[
      {id: 1, first_name: 'User1', last_name: 'New1', email: 'email@email.com'},
      {id: 2, first_name: 'User2', last_name: 'New2', email: 'email2@email.com'}
  ]
  </code></pre>
  <p>InvitationCode</p>
  <pre><code>[
      {id: 1, user_id: 1, first_name: 'invited user1', last_name: 'invited user1', email:'email_new@email.com', used: true}, 
      {id: 2, user_id: null, first_name: 'invited user2', last_name: 'invited user2', email:'email_new2@email.com', used: false}
  ]
  </code></pre>
  <p>Ideal Result:</p>
  <pre><code>first_name | last_name | email | used | user_id | invitation_code_id 
  
  User1 | New1 | email@email.com | true | 1 | 1
  
  User2 | New2 | email2@email.com | null | 2 | null
  
  invited user2 | invited user2 | email_new2@email.com | false | null | 2
  </code></pre>