The sql SELECT statement is used to select data from a SQL database tables. Syntax of the sql SELECT statement is given below.
SELECT * FROM tablename
This is the general syntax of SELECT statement in SQL. The asterix (*) symbol is indicates that the query(what we executed through SELECT statement) will return all columns from the table SELECT statement returns the ResultSet. ResultSet is nothing but its the result of our query. The result will be shown by table view.
When the asterix (*) is replaced with list of columns following the sql SELECT statement, it will return the resultset with that list of columns from table. Syntax of get list of columns from single table through sql SELECT statement.
SELECT ColumnName_1, ColumnName_2,...ColumnName_N FROM tablename
Below examples will explain this breifly. Assume that we have the following table. Table name is article_information.
| serial_no | article_code | article_name | article_price |
| 1 | CDE0001 | NOKIA | $120 |
| 2 | CDE0002 | APPLE | $340 |
| 3 | CDE0003 | RELIANCE | $220 |
| 4 | CDE0004 | SAMSUNG | $125 |
let us see the SELECT statment how work with table article_information.
Executed Query :
Select * from article_information
Result :
| serial_no | article_code | article_name | article_price |
| 1 | CDE0001 | NOKIA | $120 |
| 2 | CDE0002 | APPLE | $340 |
| 3 | CDE0003 | RELIANCE | $220 |
| 4 | CDE0004 | SAMSUNG | $125 |
Description:
Above query will return all columns in the article_information table. because we use asterix (*) symbol following the SELECT statement.
Executed Query :
Select article_name,article_price from article_information
Result :
| article_name | article_price |
| NOKIA | $120 |
| APPLE | $340 |
| RELIANCE | $220 |
| SAMSUNG | $125 |
Description:
Here we specify the column names article_name and article_price following sql statement. So the query will return only two columns from article_information table.
Executed Query :
Select article_name from article_information
Result :
| article_name |
| NOKIA |
| APPLE |
| RELIANCE |
| SAMSUNG |
Description:
Here we specify only one column name following sql statement. So the query will return list of all article names from article_information table.