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

MySQLMySQLi Database

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.

raja
Published on 19-Feb-2018 15:18:52
Advertisements