
- 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
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 Articles
- How to concatenate all columns in MySQL?
- How to display MySQL Table Name with columns?
- Find “greatest” between two columns and display with some records already null in MySql
- How to delete all rows except some in MySQL?
- How to standardize multiple columns not all in data.table object in R?
- How to display all constraints on a table in MySQL?
- How to display all the MySQL tables in one line?
- MySQL query to display ranks of multiple columns?
- How to display the column names from a table excluding some in MySQL?
- How to display all tables in MySQL with InnoDB storage engine?
- MySQL query to display custom text for empty columns
- Display all deadlock logs in MySQL?
- MySQL query to get the length of all columns and display the result in a single new column?
- How to find all tables that contains two specific columns in MySQL?
- Implement MySQL IN for 2 columns to display only selected records

Advertisements