Select Command

Select command in sql is used to retrieve the data from tables. In this Article we will only discuss how to use the select statement. See the following table which will be used in the select statement:

		
		
Emp_no Emp_fname Emp_lname Dept_no salary
102 Vishu Malhotra D-102 190000

Select All Data

When you want to retrieve all data (without filtration and specification) from any table then we use following syntax:-

		
	select * from employee;
		
		

Note: - * means all and employee is table name

Select Specific Column

When you want to select the data of specific column

		
		select emp_no, emp_fname from employee;
		
		

Note: - in this query emp_no and emp_fname is column name. there can be N number of Column

In this article we only discussed how to use the select statement.

Arithmetic Operation

We can perform following arithmetic operator with the select statement:-

1. + ( this is use for addition)
2. – (this is use for Subtraction)
3. * (this is use for Multiplication)
4. / (this is use for division which return quotient)
5. % ( this is also use for division which return Remainder)

Following are the examples of select statement using arithmetic operation:-

Add 1000 in the salary

		
select salary+1000 from employee;
		
		

Calculate employee salary in which increase 25% of Salary

		
select salary+((salary*25)/100) from employee;
		
		

Text Concatenation

When we need to concatenate the text value with the column names in this case we use + Arithmetic operator.

Check the following example:-

Suppose we want our output like this

“The Employee id of Isha Malhotra is 101”

Note: - Isha(emp_fname), Malhotra(emp_fname) and 101(emp_no)

		
select 'The Employee id of '+ emp_fname +' ' emp_lname + ' is ' + cast(emp_no as varchar) +'.' from employee;
		
		

in this example we used cast operator which is used to cast column in to specific datatype. As emp_no is Int type so first we have to cast it in to varchar so that we can concatenate this column with text.

Email Address

For any query you can send mail at info@techaltum.com
Thanks