MySQL query to select all the records only from a specific column of a table with multiple columns

MySQLi Database

To fetch records from a specific column, use the following syntax. Just select that specific column for which you want the records −

select yourColumnName from yourTableName;

Let us first create a table −

mysql> create table DemoTable
(
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   Score int
);
Query OK, 0 rows affected (0.64 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable(Score) values(89);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable(Score) values(99);
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable(Score) values(78);
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable(Score) values(75);
Query OK, 1 row affected (0.09 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+----+-------+
| Id | Score |
+----+-------+
|  1 |    89 |
|  2 |    99 |
|  3 |    78 |
|  4 |    75 |
+----+-------+
4 rows in set (0.00 sec)

Following is the query to select all the records from a specific column −

mysql> select Score from DemoTable;

This will produce the following output −

+-------+
| Score |
+-------+
|    89 |
|    99 |
|    78 |
|    75 |
+-------+
4 rows in set (0.00 sec)
raja
Published on 01-Oct-2019 07:13:54
Advertisements