Home | Add to Favorites | Ebooks Directory | News  
SQL & PL/SQL  Resources
Home
SQL , PL/SQL  Article
SQL Tutorial 
Books
SQL  Questions
SQL Code
PL/SQL Tutorial
SQL Reference
SQL Tutorial
SELECT statement with AND / OR conditional clause:

Syntax

SELECT column_name
FROM table_name
WHERE simple condition
{[AND|OR] simple condition}+

 

The {}+ means that the expression inside the bracket will occur one or more times. Note that AND and OR can be used interchangably. In addition, we may use the parenthesis sign () to indicate the order of the condition.

Example 9:


SELECT LastName FROM Employee WHERE LastName LIKE '%n';

RESULT:

Peterson




Example 10:

SELECT LastName FROM Employee WHERE LastName="Peterson" AND FirstName="John";

RESULT

Peterson

SELECT statement with LIKE Keyword:

Syntax:

SELECT column_name
FROM table_name
WHERE column_name LIKE <PATTERN>

<PATTERN> often consists of wildcards. Here are some examples:

# 'A_Z': All string that starts with 'A', another character, and end with 'Z'. For example, 'ABZ' and 'A2Z' would both satisfy the condition, while 'AKKZ' would not (because there are two characters between A and Z instead of one).

# 'ABC%': All strings that start with 'ABC'. For example, 'ABCD' and 'ABCABC' would both satisfy the condition.

# '%ABC': All strings that end with 'ABC'. For example, 'XYZABC' and 'ZZABC' would both satisfy the condition.
 
# '%AN%': All string that contain the pattern 'AN' anywhere. For example, 'INDIANS' and 'SWANS' would both satisfy the condition