|
|
|
Oracle SQL SELECT Statement
SQL Queries, SELECT StatementUse a SELECT statement or subquery to retrieve data from one or more tables, object tables, views, object views, or materialized views For example to retrieve all rows from emp table. SQL> select empno, ename, sal from emp;
Or (if you want to see all the columns values You can also give * which means all columns)
SQL> select * from emp;
Suppose you want to see only employee names and their salaries then you can type the following statement
SQL> select name, sal from emp;
Filtering Information using Where Conditions
You can filter information using where conditions like suppose you want to see only those employees whose salary is above 5000 then you can type the following query with where condition
SQL>select * from emp where sal > 5000; To see those employees whose salary is less than 5000 then the query will be SQL> select * from emp where sal < 5000; Logical ConditionsA logical condition combines the results of two component conditions to produce a single result based on them or to invert the result of a single condition. Table below lists logical conditions.
Membership Conditions A membership condition tests for membership in a list or subquery The following table lists the membership conditions.
Null ConditionsA NULL condition tests for nulls. What is null? If a column is empty or no value has been inserted in it then it is called null. Remember 0 is not null and blank string is also not null. The following example lists the null conditions.
EXISTS ConditionsAn EXISTS condition tests for existence of rows in a subquery. The following example shows the EXISTS condition.
LIKE ConditionsThe LIKE conditions specify a test involving pattern matching. Whereas the equality operator (=) exactly matches one character value to another, the LIKE conditions match a portion of one character value to another by searching the first value for the pattern specified by the second. LIKE calculates strings using characters as defined by the input character set. For example you want to see all employees whose name starts with S char. Then you can use LIKE condition as follows SQL> select * from emp where ename like S% ; Similarly you want to see all employees whose name ends with d SQL>select * from emp where ename like %d; You want to see all employees whose name starts with A and ends with d like Abid, Adward, Arnold. SQL>select * from emp where ename like A%d; You want to see those employees whose name contains character a anywhere in the string. SQL> select * from emp where ename like %a%; To see those employees whose name contains a in second position. SQL>select * from emp where ename like _a%; To see those employees whose name contains a as last second character. SQL>select * from emp where ename like %a_; To see those employees whose name contain % sign. i.e. % sign has to be used as literal not as wild char. SQL> select * from emp where ename like %\%% escape \; |
|
|