How can we fetch one or more columns as output from a MySQL table?


The SELECT command can be used to fetch one or more columns as output from MySQL table. An 

 example is given below to fetch one or more columns

mysql> Select * from Student;

+------+---------+---------+-----------+
| Id   | Name    | Address | Subject   |
+------+---------+---------+-----------+
| 1    | Gaurav  | Delhi   | Computers |
| 2    | Aarav   | Mumbai  | History   |
| 15   | Harshit | Delhi   | Commerce  |
| 17   | Raman   | Shimla  | Computers |
+------+---------+---------+-----------+

4 rows in set (0.01 sec)

mysql> Select Name,Subject from Student;

+---------+-----------+
| Name    | Subject   |
+---------+-----------+
| Gaurav  | Computers |
| Aarav   | History   |
| Harshit | Commerce  |
| Raman   | Computers |
+---------+-----------+

4 rows in set (0.00 sec)

The query above fetches two columns ‘Name’ and ‘subject’ from ‘Student’ table.

mysql> Select Address from Student;

+---------+
| Address |
+---------+
| Delhi   |
| Mumbai  |
| Delhi   |
| Shimla  |
+---------+

4 rows in set (0.00 sec)

The query above fetches only one column ‘Address’ from ‘Student’ table.

Updated on: 29-Jan-2020

168 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements