

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to display some columns (not all) 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)
- Related Questions & Answers
- How to concatenate all columns in MySQL?
- How to display MySQL Table Name with columns?
- How to delete all rows except some in MySQL?
- How to standardize multiple columns not all in data.table object in R?
- Find “greatest” between two columns and display with some records already null in MySql
- MySQL query to display ranks of multiple columns?
- Display all deadlock logs in MySQL?
- How to display the column names from a table excluding some in MySQL?
- How to display all constraints on a table in MySQL?
- How to display all the MySQL tables in one line?
- Using UNIQUE for varchar columns with some conditions in MySQL?
- MySQL query to display custom text for empty columns
- How to standardize columns if some columns are categorical in R data frame?
- How to scale some columns in data.table object in R?
- How to display all tables in MySQL with InnoDB storage engine?
Advertisements