Counting Table Columns in MySQL
Determining the number of columns in a MySQL table can be useful for various applications. Here's how you can retrieve this information efficiently:
Query:
To count the columns in a table named "tbl_ifo," you can execute the following query:
SELECT count(*) FROM information_schema.columns WHERE table_name = 'tbl_ifo'
Explanation:
Sample Data:
As an example, consider the following table:
Column 1 | Column 2 | Column 3 |
---|---|---|
1 | John | 15 |
2 | Maria | 18 |
3 | Steph | 19 |
4 | Jay | 21 |
Result:
Executing the count query on this table would return:
count(*) --------- 3
Therefore, the sample table contains a total of three columns.
The above is the detailed content of How to Count the Number of Columns in a MySQL Table?. For more information, please follow other related articles on the PHP Chinese website!