
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements