Looking for suggestions on how to auto increment a field based on a field from an outside table.

For instance, if InvoiceNo is in InvoiceTable and CompanyName is in CompanyTable, would like to have sequential auto numbering of InvoiceNo for a given CompanyName.

I'm working with MySQL, but the concept should be similar for any database no?