using an existing token as a variable in a custom token
Accessing the database to set a token is not different from accessing the database in other cases.

function mymodule_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $sanitize = !empty($options['sanitize']);

  $replacements = array();

  if ($type == 'YOUR TOKEN TYPE') {
    foreach ($tokens as $name =&gt; $original) {
      switch ($name) {
        case 'YOUR TOKEN':
          $replacements[$original] = /* CODE TO QUERY THE DATABASE */;
          break;
      }
    }
  }

  return $replacements;
}


As for accessing the value of a token defined from a module, when you know the token you are looking for, you can call token_replace() passing the token for which you want to know the value as first parameter. Keep in mind that your implementation of hook_tokens() is going to be called again; be careful of not causing a loop.