Reputation: 3981
I need to accomplish a purely administrative scripting task in mysql and I'd like to do it without writing a perl or php script or something.
Given the following Table A
:
user_id | permission
--------------------
1 1
4 1
298 1
How would I give every user_id
present in Table A
the permission
5. (It needs to insert a new row for each user_id
present in the table)
Upvotes: 0
Views: 51
Reputation: 2429
insert into tableA (user_id, permission)
select distinct user_id, 5 from tableA
To give every unique user a new permission entry.
Upvotes: 0
Reputation: 51928
To insert for each user in the table another row with permission 5 you can do
INSERT INTO TableA (user_id, permission)
SELECT DISTINCT user_id, 5
FROM TableA;
Upvotes: 2