
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL Select displaying Data type in a separate column?
You can use INFORMATION_SCHEMA.COLUMNS for this. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20) ); Query OK, 0 rows affected (0.73 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(Name) values('Robert'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable(Name) values('Sam'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+--------+ | Id | Name | +----+--------+ | 1 | Chris | | 2 | Robert | | 3 | Sam | +----+--------+ 3 rows in set (0.00 sec)
Following is the query to display data type and data value −
mysql> SELECT DemoTable.Name, col1.DATA_TYPE FROM DemoTable,INFORMATION_SCHEMA.COLUMNS col1 WHERE col1.TABLE_NAME='DemoTable' AND COLUMN_NAME='Name';
This will produce the following output −
+--------+-----------+ | Name | DATA_TYPE | +--------+-----------+ | Chris | varchar | | Robert | varchar | | Sam | varchar | +--------+-----------+ 3 rows in set (0.04 sec)
- Related Articles
- Select * but ignore displaying results containing a specific character in MySQL
- Add a new value to a column of data type enum in MySQL?
- How to alter the data type of a MySQL table’s column?
- How to add subtotal to a table column displaying NULL in MySQL?
- Selecting and displaying only some rows from a column in a MySQL table
- Can we GROUP BY one column and select all data in MySQL?
- Select column names containing a string in MySQL?
- Select MySQL rows where column contains same data in more than one record?
- Select data and set value to boolean based on timestamp column in MySQL
- MySQL query to select a count on two separate conditions?
- MySQL query to separate and select string values (with hyphen) from one column to different columns
- How to SELECT * and rename a column in MySQL?
- Create a rolling mean column by displaying means to corresponding values in R data frame.
- How can we change the data type of the column in MySQL table?
- Show column value twice in MySQL Select?

Advertisements