Home Tutorials IT Jobs Source Codes Certifications Discussion Forum
  SQL Tutorials
SQL SELECT
SQL DISTINCT
SQL WHERE
SQL AND OR
SQL IN
SQL BETWEEN
SQL LIKE
SQL ORDER BY
SQL FUNCTIONS
SQL COUNT
SQL GROUP BY
SQL HAVING
SQL ALIAS
SQL JOIN
SQL OUTER JOIN
SQL CONCATENATE
SQL SUBSTRING
SQL TRIM
SQL CREATE TABLE
SQL CONSTRAINT
SQL PRIMARY KEY
SQL FOREIGN KEY
SQL CREATE VIEW
SQL CREATE INDEX
SQL ALTER TABLE
SQL DROP TABLE
SQL TRUNCATE TABLE
SQL INSERT INTO
SQL DELETE FROM
   IT Jobs
Software Jobs
Networking Jobs
   Model Question Papers
BE Computer Science
MCA
BCA
Others
 
   

SQL AND OR

In the previous section, we have seen that the WHERE keyword can be used to conditionally select data from a table. This condition can be a simple condition (like the one presented in the previous section), or it can be a compound condition. Compound conditions are made up of multiple simple conditions connected by AND or OR. There is no limit to the number of simple conditions that can be present in a single SQL statement.

The syntax for a compound condition is as follows:

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 interchangeably. In addition, we may use the parenthesis sign () to indicate the order of the condition.

For example, we may wish to select all stores with sales greater than $1,000 or all stores with sales less than $500 but greater than $275 in Table Store_Information,

Table Store_Information 

store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
San Francisco $300 Jan-08-1999
Boston $700 Jan-08-1999


SELECT store_name
FROM Store_Information
WHERE Sales > 1000
OR (Sales < 500 AND Sales > 275)

Result:

store_name 
Los Angeles 
San Francisco 

<< Previous | Next >>

Home  |  About us  | Privacy  |  Disclaimer  |  Contact us |  Advertise with us | Our Link Partners
All Rights Reserved 2009, CodeTeller.com