How can I update a column between two unique values in another column in MySQL or MariaDB?
Consider a table called Example that has three columns:
- Id: An auto-increment integer ID
- RandomId: A series of random and unique GUIDs
- IsUpdated: A column currently only containing NULL values, that needs to be updated
* ----------------------------------------------------- *
| Id | RandomId                             | IsUpdated |
| ----------------------------------------------------- |
| 1  | c446980b-cf2f-4f2d-a27b-28d6bde6415d | NULL      |
| 2  | d6a1a52c-d073-4019-836a-67cf6551d958 | NULL      |
| 3  | 7a339a6a-8e57-4373-84fd-1b40ee51c884 | NULL      |
| 4  | 56b908a7-fb07-4f4c-a25d-699cf40cf690 | NULL      |
| 5  | fac75ce6-a605-453a-958c-74f197e20a11 | NULL      |
* ----------------------------------------------------- *
I would like to update IsUpdated between two specific GUIDs, like so:
UPDATE Example
   SET IsUpdated = 1
 WHERE RandomId >= 'd6a1a52c-d073-4019-836a-67cf6551d958' -- Starting Here
   AND RandomId <= '56b908a7-fb07-4f4c-a25d-699cf40cf690' -- Ending Here
The resulting table should look like the following:
* ----------------------------------------------------- *
| Id | RandomId                             | IsUpdated |
| ----------------------------------------------------- |
| 1  | c446980b-cf2f-4f2d-a27b-28d6bde6415d | NULL      |
| 2  | d6a1a52c-d073-4019-836a-67cf6551d958 | 1         |
| 3  | 7a339a6a-8e57-4373-84fd-1b40ee51c884 | 1         |
| 4  | 56b908a7-fb07-4f4c-a25d-699cf40cf690 | 1         |
| 5  | fac75ce6-a605-453a-958c-74f197e20a11 | NULL      |
* ----------------------------------------------------- *
But since the Ids are not sequential, this method does not appear to work.
What would be the most efficient way to update a column (IsUpdated) between two unique values in another column (RandomId)?
 
    