Skip to content
Advertisement

sql: simple question, how to see data from columns with similar names?

With this query on mysql I can see the delete_priv value

select user,Delete_priv  from user ;

I see there is a lot of _priv columns, how to see all priv values? I have tried

select user,*_priv  from user ;
select user,%%priv%% from user;

But is wrong syntax.

Advertisement

Answer

No.

In standard SQL, you need to enumerate all names of the columns you want to select. Or, you can use select *, and get all the columns in the table.

Alternatively, you can use dynamic SQL: that is, write a query that searches information_schema.columns and generates the list of columns that matches your filter, concatenate a query string from that, then execute it. But this is really a more complex beast, that is probably overkill for your use case.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement