How do I build a query using information_schema for all columns in one sql query?

I’m trying to check if any of the values changed in an audit table. But the table has a large number of columns that I need to list manually using lag and partition so I’m thinking of using information_schema to save some time because I have at least 10 tables to query.

However, I’m not sure how to put two of them together into one query

Like I can list all of the columns using this query

select column_name from information_schema.columns  where table_name = 'history'; 

and that would give me all the columns

And I have this query to list out the changes

select nullif(name, lag(name) over (order by mod_date)) as name,        mod_date,        nullif(create_user_id, lag(create_user_id) over (order by mod_date)) as create_user_id,        nullif(is_active, lag(is_active) over (order by mod_date)) as is_active from history where id = 001 order by mod_date; 

How do I use information_schema.columns to list all the columns in the select statement and execute that in one query?

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.