I have a table with the following structure:
| ID | abc1 | abc2 | abc3 | def1 | def2 | def3 |
|----|--------|--------|--------|--------|--------|--------|
| 1 | Text 1 | Text 2 | Text 3 | Text A | Text B | Text C |
| 2 | Text 4 | Text 5 | Text 6 | Text D | Text E | Text F |
I now want to get the contents of all columns starting with abc
.
With
select column_name from information_schema.columns
where table_name='tab1'
and (column_name like 'abc%')
I get the required columns:
abc1
abc2
abc3
How can I get their content as well? So the desired output would be:
| abc1 | abc2 | abc3 |
|--------|--------|--------|
| Text 1 | Text 2 | Text 3 |
| Text 4 | Text 5 | Text 6 |
My approach was to put that query in another query, like that:
select (select column_name from information_schema.columns
where table_name='tab1'
and (column_name like 'abc%'))
from tab1
But I get this error:
Subquery returns more than 1 row