Display Selected Columns in MySQL



In order to show some columns, use NOT IN and set those columns which you do not want to display. Let us first create a table. Following is the query −

mysql> create table student_Information
   -> (
   -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> StudentName varchar(50),
   -> StudentAge int,
   -> StudentAddress varchar(100),
   -> StudentAllSubjectScore int
   -> );
Query OK, 0 rows affected (0.69 sec)

Following is the query to display a description about the above table −

mysql> desc student_Information;

This will produce the following output −

+------------------------+--------------+------+-----+---------+----------------+
| Field                  | Type         | Null | Key | Default | Extra          |
+------------------------+--------------+------+-----+---------+----------------+
| StudentId              | int(11)      | NO   | PRI | NULL    | auto_increment |
| StudentName            | varchar(50)  | YES  |     | NULL    |                |
| StudentAge             | int(11)      | YES  |     | NULL    |                |
| StudentAddress         | varchar(100) | YES  |     | NULL    |                |
| StudentAllSubjectScore | int(11)      | YES  |     | NULL    |                |
+------------------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

Following is the query to display only some columns −

mysql> SHOW COLUMNS FROM student_Information where field not
in('StudentAddress','StudentAllSubjectScore');

This will produce the following output −

+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| StudentId   | int(11)     | NO   | PRI | NULL    | auto_increment |
| StudentName | varchar(50) | YES  |     | NULL    |                |
| StudentAge  | int(11)     | YES  |     | NULL    |                |
+-------------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
Updated on: 2019-07-30T22:30:25+05:30

243 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements