Bugzilla:SQLCookBook: Difference between revisions

Jump to navigation Jump to search
Line 69: Line 69:
  CM class.\n\> Wasn't someone in the Software Competency going to put together a CVS class?\n\nSee bu
  CM class.\n\> Wasn't someone in the Software Competency going to put together a CVS class?\n\nSee bu
  g 1555 (my request for a CVS training class)\n'  where comment_id=4520;
  g 1555 (my request for a CVS training class)\n'  where comment_id=4520;
===Add everyone to a particular group===
select id from groups where name = "MyProduct";
+----+
| id |
+----+
| 45 |
+----+
1 row in set (0.00 sec)
We then get all the rows from profiles, add on the groups.id we just got, one '0' to say that this is just a regular user, not one who can grant this power to others, and that their inclusion is explicit.  The insert ignore says "Yeah, I know we are trying to insert duplicate rows, but don't stop going, you're allowed to fail to insert the row, IGNORE that error.
insert ignore into user_group_map select userid, 45, 0, 0 from profiles;
Note that if you wanted to replace any duplicate rows with your version (removing a blessing, for instance), you could add '''on duplicate key update'''. See the MySQL manual for more info. Further note that IGNORE and ON DUPLICATE KEY UPDATE are not mutually exclusive. IGNORE really means to turn '''all''' errors into warnings.
16

edits

Navigation menu