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
)
Popular Posts
-
public - public means everyone can access it.That means it's in global scope. As, main method is called by JVM [ Java Virtual Machine...
-
throw is used to throw an exception in a program, explicitly . Whereas, throws is included in the method's declaration part, wi...
-
Singleton in one of the most popular yet controversial design pattern, in the world of object oriented programming. It's one of t...
-
Web Container / Servlet Container / Servlet Engine : In J2EE Architecture , a web container (also known as servlet container or ser...
-
Program compiles. But at runtime throws an error “NoSuchMethodError”.
-
Vector : It's synchronized. It's slower than ArrayList. It's generally used in ...
-
doGet(): protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, java.io.IOException – is a met...
-
In Java Programming Language , we must declare a variable name and type, before using it. The data type of a variable defines the th...
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