Question

Let's say I have table 'items'.
There are 500 rows in table 'items'.
I want to add a new column, 'new'.
Rows 1 - 100 need to have 'A' in column 'new',
Rows 101 - 200 need to have 'B' in column 'new',
Rows 201 - 300 need to have 'C' in column 'new'.
Etc, etc.

so:

Is there a mysql query to do something like:

UPDATE items WHERE rows 1 THROUGH 100 (UPDATE 'A' IN new)
Was it helpful?

Solution

Try this:

For 1-100

    UPDATE table
    set new = 'A'
    where id in 
    (
     Select temp.Id from
     ( 
       Select id as Id from table limit 1,100
      ) as temp
   )

For 101-200

    UPDATE table
    set new = 'B'
    where id in 
    (
     Select temp.Id from
     ( 
       Select id as Id from table limit 101,100
      ) as temp
   )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top