PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 19, 2022

[FIXED] Assign random numbers to a column with NULL values in mySQL

 January 19, 2022     mysql, phpmyadmin     No comments   

Issue

I have a table named employees and a column named group. Now, upon checking the table, the column has NULL values and I want to assign them a proper numbers from 1 to 10. Can anyone help me on this one? I don't know where to start, please note that i want to update the values that are NULL only.


Solution

Try this update:

UPDATE employees
SET `group` = FLOOR( 1 + RAND( ) *10 )
WHERE `group` IS NULL;

As a side note, GROUP is a MySQL reserved keyword, and you should avoid naming your columns etc. using it.



Answered By - Tim Biegeleisen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing