Question: I want to execute a SELECT query but I don't how many columns to select.

Like:

```
select name, family from persons;

```

How can I know which columns to select?

"I am currently designing a site for the execute query by users.
So when the user executes this query, I won't know which columns selected.
But when I want to show the results and draw a table for the user I should know which columns selected."

Answer: 
First, understand exactly what data you want to retrieve. Then look at the database schema to find out which tables the database contains, and which columns the tables contain.

The following query returns a result set of every column of every table in the database:

```
SELECT table_name, column_name
FROM INFORMATION_SCHEMA.COLUMNS;

```

In this [sqlfiddle](http://sqlfiddle.com/#!2/d41d8/1073), it returns the following result set (truncated here for brevity):

```
TABLE_NAME  COLUMN_NAME
-----------------------
CHARACTER_SETS  CHARACTER_SET_NAME
CHARACTER_SETS  DEFAULT_COLLATE_NAME
CHARACTER_SETS  DESCRIPTION
CHARACTER_SETS  MAXLEN
COLLATIONS  COLLATION_NAME
COLLATIONS  CHARACTER_SET_NAME
COLLATIONS  ID
COLLATIONS  IS_DEFAULT
COLLATIONS  IS_COMPILED
COLLATIONS  SORTLEN

```

Now I know that I can select the column CHARACTER\_SET\_NAME from the table CHARACTER\_SETS like this:

```
SELECT CHARACTER_SET_NAME
FROM CHARACTER_SETS;

```

Use [`mysqli::query`](http://www.php.net/manual/en/mysqli.query.php) to execute these queries.
use `DESC table` or

**Example**

```
SELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name='your_table';

```

**output**

```
 column1,column2,column3

```