Q:

How do you query rows with regex that includes column values

I've got a table where identifiers(XXXXX-065-00) should match a division(65). I'd like to query all the rows that don't match. 
The following SQL seems to work, but is there a better or more efficient way of doing this? 
select id,division,identifier from table where identifier not REGEXP '.....-'+division+'-..'

A:

You can concat() the regex string:
where identifier not regexp concat('^.{5}-', lpad(division, 3, '0'), '-..$')

Note that in MySQL + is a numeric addition (it does not do string concatenation, like in SQL Server for example).
Other remarks:

you probably need to pad the division with '0's so it has exactly 3 characters
I added ^/$ to make the regex match on the entire string rather than do partial matching, since this seems to be what you want
you can use quantifiers: .{5} stands for .....

