If I understand your question correctly, your table names are confusing, I think this is partially why you haven't had a response. If you can re-name
Roles
to
UserGroups
, or better yet rename
Roles
to
UserRoles
and
Groups
to
Roles
then this will improve the understandibility of your tables, it current looks like you want to be able to assign users to both groups and roles (which is something a lot of people actually want to do).
Before you make the changes, the SQL will be something like:
INSERT INTO
ROLES (UserId,GroupId)
SELECT
UserId,
GroupId
FROM
Users,
Groups
WHERE
UserName= 'Ali'
AND
GroupName='Administrator'
You should
parameterise this query to avoid SQL injection[
^] so 'Ali' and 'Administrators' become parameters.
As for rolling it up into one table: don't. As Christain said in his [deleted] reply it will result in you only being able to assign one role to each user, this is almost certainly not what is needed as users normally have multiple roles.