How to maintain unique sequence across table columns?
Plan A:  Have a 3rd table that contains an AUTO_INCREMENT plus any common columns between the two existing tables.

Plan B:  Build a "sequence" table which has 2 columns:  an AUTO_INCREMENT and another column to key into the table.  Probably REPLACE is the command to get a new id without growing the table.

REPLACE is performed in 2 steps:


DELETE any row(s) that have match on any UNIQUE key.
INSERT a new row.


Here's the table and its initialization:

    CREATE TABLE sequence (
        seq INT UNSIGNED AUTO_INCREMENT NOT NULL,
        code CHAR(1) CHARACTER SET ascii NOT NULL,
        PRIMARY KEY(seq),
        UNIQUE(code) ) ENGINE = InnoDB;
    INSERT INTO sequence (seq, code) VALUES (1, 'a');


To get the new 'next' sequence number, either use REPLACE:

    REPLACE INTO sequence (code) VALUES ('a');
    SELECT seq FROM sequence WHERE code = 'a';


Or, and this is probably faster,

    INSERT INTO sequence (seq, code)
        VALUES (NULL, 'a')
        ON DUPLICATE KEY UPDATE
            seq = LAST_INSERT_ID(seq + 1);
    SELECT LAST_INSERT_ID();