Conditional Retrieval Assignment Help

Assignment Help: >> Basics of SQL - Conditional Retrieval

Conditional Retrieval

Conditional retrieval enables selective rows to be selected. Although selecting rows, restriction can be applied by a condition which governs the selection. Further clause called WHERE must be provided along with the SELECT statement to apply the condition to select a specific set of rows.The order of prior first goes to the WHERE clause and the records that match the condition are alone selected.

Syntax:

Select (column name(s)) FROM (table name(s)) WHERE condition(s)  
Let consider selecting employee records whose salary is equivalent to or greater than 3000. The query can be written as follows,

Example:

SELECT empno,empname,salary FROM employee where salary >=3000; The records selected will be,

2458_Conditional Retrieval.png

Example:

# for select the employee who have 1000 salary# SELECT * FROM employee WHERE salary=1000;
The display would be no rows selected because there are no records matching the condition specified in the WHERE clause.

Retrieving Records in a sorted order

Records selected can be displayed in two forms either in ascending order or in descending order based on the column specified. The ORDER BY clause is used to perform this operation.

Syntax:

Select (column name(s))
FROM (table name(s)) WHERE condition(s) ORDER BY <column name(s)>

Example:

# for select the employee by name order# SELECT * FROM employee ORDER BY empname;
This would shows

462_Conditional Retrieval 1.png

There is a difference in the looks. This query displays all the records in the employee table sorted in ascending order of the employee name. Ascending is the order by default in that the records are displayed. If the record needs to be displayed in descending order, use DESC along with the column name.

Instance, selecting employee via name in descending order SELECT * FROM employee ORDER BY empname DESC;Here list will be sorted in the descending order. So the looks will be totally different as shown as follows:

415_Conditional Retrieval 2.png

Sorting records can be done on more than one column. In that case, sorting is done on the first column and then within that sorting is done on the second column. The following example describes this.

Consider that sorting is to be done on the salary column in ascending order and then within that on the empname column in descending order.SELECT empno,empname,salary FROM employee ORDER BY salary,empname DESC; This query sorts first the salary and within that the employee name that would look like:

880_Conditional Retrieval 3.png

Note: DESC indicates descending order and this is not the similar as DESC in SQL * Plus.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd