def get_user_groups(db, user_id=None):
    """Retrieves the existing user groups,
       if member_is is provided returns
       only the groups associated to the user_id

    Args:
        db (object): The db object
        user_id (int): User ID

    Returns:
        The user groups
    """
    sql = '''SELECT id, name, description
             FROM user_group ug '''
    if user_id is not None:
        sql += '''JOIN user_group_has_user ughu ON ughu.user_group_id = ug.id
                  WHERE ughu.user_id=?'''

    args = (user_id,) if user_id is not None else None
    return db.select(sql, args)