I have a schema in MySQL with many tables that all use the same column name for their primary key, id
, which is a bigint
in all tables. What I need is a query that will find the maximum value of id
across all rows across all tables. Alternatively I would settle for a list of the max id
values of each table, which I could then sort.
I have this which will list all tables that have the id
column, but leaping from there to selecting the columns across those tables is beyond my SQL skills:
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'id'