First thing is first, download and install the Sourcerer plugin which will allow you to add custom code to your articles.
One done, open your article and click the "Add Code" button below the textarea. Here you can add you custom code.
I'll write more or less the query you want using Joomla coding standards which most people seem to forget about:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('favorite_color')))
->from($db->quoteName('colors'))
->where($db->quoteName('name') . ' = '. $db->quote('bob'));
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
echo $row->favorite_color;
}
Notes that if the colors
tables belongs to a Joomla extensions, then use #__colors
Hope this helps