public function registerTable($name, $alias)
    {
        if (!empty($alias) && empty($name))
            return;

        if (!empty($alias) && !empty($this->parent_scope))
        {
            $table = $this->parent_scope->resolveAlias($alias); 
            if (!empty($table))
                throw new QueryException("Duplicate alias \"$alias\" - was already bound to \"$table\" in parent scope");
        }

        if (isset($this->tables[$name]))
        {
            if (empty($alias))
                throw new QueryException("Duplicate table without an alias: \"$name\"");
            if (isset($this->tables[$name][$alias]))
                throw new QueryException("Duplicate alias \"$alias\" for table \"$name\"");
            if (isset($this->tables[$name][$name]))
                throw new QueryException("All instances of a table reference must be aliased if used more than once");

            $this->tables[$name][$alias] = true;
            $this->aliases[$alias] = $name;
        }
        elseif (!empty($alias) && is_string($alias))
        {
            if (isset($this->aliases[$alias]))
                throw new QueryException("Duplicate alias \"$alias\" for table \"$name\" - also referring to \"{$this->aliases[$alias]}\"");
            $this->aliases[$alias] = $name;
            $this->tables[$name][$alias] = true;
        }
        else
        {
            $this->tables[$name][$name] = true;
        }
        return $this;
    }