0

Hi i have this tow tables:

mysql> select username from users where username like '%';

username
admin
datacenter
network
noc-operator
storage-operator
tgdwaro2 <---
ws-user

mysql> select name from roles where name like '%';

name
Full Control Users
Storage Administrator Users
Network Administrator Users
NOC Operator Users
Datacenter Administrator Users
Web Service Role
user_role <----------

Hier the columns from the tow tables 'roles' and 'users':

mysql> show columns from roles;

Field Type Null Key Default Extra
id int(10) unsigned NO PRI NULL
name varchar(50) NO NULL
description text YES NULL
parent int(10) unsigned YES NULL
filter text YES NULL
disabled tinyint(1) NO 0

mysql> show columns from users;

Field Type Null Key Default Extra
id int(10) unsigned NO PRI NULL
username varchar(50) NO UNI NULL
password varchar(100) YES NULL
title varchar(10) YES NULL
firstname varchar(50) YES NULL
lastname varchar(50) YES NULL
rolename varchar(15) NO NULL
email varchar(50) YES NULL
treetemplate longtext YES NULL
masterfilter text YES NULL
disabled tinyint(1) NO 0

What i need it's that at the user 'tgdwaro2' from table 'users' i can ad this role 'user_role' from the table 'roles' with a update/select.

Kind Regards and Thank you Roland


Hi Baram I am a beginner in MySql. Thanks for you Help the Select from you works but the result it's not that wat i need. It's my fault i have to explane better :-).

I try this:

(mysql> UPDATE users SET username = (SELECT name from roles where name like 'user_role') WHERE username = 'tgdwaro2';)

mysql> select username from users where username like '%';

username
admin
datacenter
network
noc-operator
storage-operator
user_role <--befor was tgdwaro2
ws-user

Wat i need it's that at the user 'tgdwaro2' ad's this role 'user_role' and not change the user name. Kind Regards and Thank you Roland

  • `UPDATE users SET username = (SELECT ...) WHERE username = 'tgdwaro2'` – Barmar Apr 11 '23 at 18:11
  • If you want to clarify, click the `Edit` button below the question and update it. It's hard to read code in comments. – Barmar Apr 12 '23 at 16:31
  • `where username like '%'` will match all users, since `%` is a wildcard that matches anything. – Barmar Apr 12 '23 at 16:31
  • Please show the two tables with all relevant columns, and then what you want the changed table to look like. – Barmar Apr 12 '23 at 16:32

0 Answers0