Sunday, 17 February 2013
SQL: SELECT Command
Do you like this Article?
SELECT command is use in SQL to "SELECT [some info] FROM [a location]". Now, this is the basic structure of the SELECT query, where SELECT and FROM are 2 commands of SQL. Here, [some info] part will be the column names separated by comma (,) sign and [a location] part will be the name of the Table or View. So, the syntax will be :
For Single Column :
Syntax : SELECT [Column_name] FROM [Table_Name];
For Multiple Columns :
Syntax : SELECT [Column1_name, Column2_name, Column3_name] FROM [Table_Name];
Now, what if you want to select all the columns of a table or a view. Do you have to write all the column name for that. No necessarily, you can user the star (*) sign in [Column_name] area. Then the syntax will be:
For All Columns :
Syntax : SELECT * FROM [Table_Name];
Example:
Suppose there is a table to keep
Employee Details (Table Name: employee_details), which contains
Employee ID(Column Name: emp_id),
Employee Name(Column Name: emp_name),
Employee Address:(Column Name: emp_address) and
Employee Role: (Column Name: emp_role).
Table: employee_details
Now, to select emp_id and emp_name from the table, the query will be,
SELECT emp_id, emp_name FROM employee_details;
Result:
Again, if you wants to select all the colunms' record, then the query will be,
SELECT * FROM employee_details;
Result:
For Single Column :
Syntax : SELECT [Column_name] FROM [Table_Name];
For Multiple Columns :
Syntax : SELECT [Column1_name, Column2_name, Column3_name] FROM [Table_Name];
Now, what if you want to select all the columns of a table or a view. Do you have to write all the column name for that. No necessarily, you can user the star (*) sign in [Column_name] area. Then the syntax will be:
For All Columns :
Syntax : SELECT * FROM [Table_Name];
Example:
Suppose there is a table to keep
Employee Details (Table Name: employee_details), which contains
Employee ID(Column Name: emp_id),
Employee Name(Column Name: emp_name),
Employee Address:(Column Name: emp_address) and
Employee Role: (Column Name: emp_role).
Table: employee_details
Now, to select emp_id and emp_name from the table, the query will be,
SELECT emp_id, emp_name FROM employee_details;
Result:
SELECT * FROM employee_details;
Result:
Subscribe to:
Post Comments
(
Atom
)

.bmp)
.bmp)
.bmp)

1 Responses to “ SQL: SELECT Command ”
21 February 2013 at 13:56
Good to see the SQL learning in this blog. SQL is easy command base language but difficult to learn for so many people specially for new web programmers.
Post a Comment