title: SQL insert a User role
body: <p>I have the following users/roles table structure in a database. And I want to set a role (for example, "CUSTOMER" for a user). So that the role id will be inserted into the User_Roles table as well as the appropriate user id. What is the correct SQL query for that?</p>
  
  <p>I tried this: </p>
  
  <pre><code>INSERT INTO user_roles (user_id, role_id)
  SELECT users.id, 3
  FROM users
  WHERE users.id = 1
  </code></pre>
  
  <p>Is there a better way to do that?</p>
  
  <pre><code>---- Users Table ---------
  ID | UserName | Password
   1 | SomeUser | *****
  --------------------------
  
  ---- Roles Table ---------
  ID | Role
   1 | CUSTOMER
   2 | ADMIN
  --------------------------
  
  ---- User_Roles Table ---------
  UserID | RoleID
       1 |      1
       1 |      2
  -------------------------------
  </code></pre>