
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Select Records from a Specific Column in MySQL
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)
Advertisements