从表中获取用户,其中group =另一个表行的组,但我有其他表行的id

MY USERS TABLE:

enter image description here

GROUP_PERMISSIONS TABLE

enter image description here

problem:

How can i get all the users(from users table) with the group i.e equal to the group of groups_permissions table but i have the gid of the group from groups_permissions table?

CODE:(that i have tried(it has some other functions also))

$stmt = $db_con->query("SELECT gp.*, s.*, uu.*, ug.* FROM (SELECT * FROM groups_permissions WHERE gid={$_POST['gp_row_id']}) gp, (SELECT * FROM settings WHERE id='1') s, (SELECT username FROM users ORDER BY id) uu, (SELECT username FROM users WHERE `group`=gp.group_name WHERE gp.gid={$_POST['gp_row_id']}) ug");            
$stmt->execute();
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
    /* FROM GROUP_PERMISSIONS TABLE */
        $response['id'] = $row['gid'];
        $response['group'] = $row['group_name'];
        $response['restricted_pages'] = $row['restricted_pages'];
        $response['restricted_permissions'] = $row['restricted_permissions'];
    /* FROM SETTINGS TABLE */
        $response['site_pages'] = $row['site_pages'];
        $response['site_permissions'] = $row['site_permissions'];
    /* FROM USERS TABLE */
        $active_ids[]= $row['username'];
        $userlist = join(",", $active_ids);
        $string = trim($userlist,'"');
        $response['users'] = $string;
    }
    echo json_encode($response);

FOR EXAMPLE if on submitting the form i get the row id 5 (see image above) of a group dsf from groups_permissions ,then i want to get all users with group dsf from users table but as i have the id for group from groups_permissions table then ,i dont know what to use but like Select username from users WHERE group='dsf' from permissions_table but rather select the group by the help of gid

If I got it right, select should be

"SELECT *
FROM users
INNER JOIN permissions_table ON permissions_table.group_name = users.group
WHERE permissions_table.gid = {$_POST['gp_row_id']}"

And I would advice to keep group IDs in users table, instead of group names, as it is proper practice for relational databases.