Professional Documents
Culture Documents
Syntax:
For example:
select distinct *
FROM AGENTS
The following SQL statement lists the number of different (distinct) customer
countries:
SELECT COUNT(DISTINCT working_area) FROM AGENTS;
WHERE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;
The WHERE clause is not only used in SELECT statements, it is also used
in UPDATE, DELETE, etc.!
Example
SELECT * from AGENTS where working_area='Bangalore';
SELECT AGENT_CODE , AGENT_NAME from AGENTS where working_area='Bangalore'
Example
select * from CUSTOMER where GRADE> 2 AND OPENING_AMT> 6000
SELECT * FROM CUSTOMER WHERE GRADE> 2 OR OPENING_AMT> 6000
select * from CUSTOMER where CUST_CITY='Bangalore' and
CUST_COUNTRY='India'
select * from CUSTOMER where CUST_CITY='Bangalore' or CUST_COUNTRY='India'
SELECT * FROM CUSTOMER WHERE NOT CUST_CITY='Bangalore';
The following example finds the phone numbers and emails of contacts
whose first names have the following pattern 'Je_i':
The pattern 'Je_i' matches any string that starts with 'Je', followed by one
character, and then followed by 'i' e.g., Jeri or Jeni, but not Jenni
the following statement finds contacts whose first names that have "r" in the
second position:
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;
IS NULL
NULL is
special. It is a marker for missing information or the information is
not applicable.
NULL is special in the sense that it is not a value like a number, character
string, or datetime,
you cannot compare it with any other values like zero (0) or an empty string
(”).
IS NULL EXAMPLE
The following query returns all sales orders that do not have a responsible
salesman:
IS NOT NULL
the following example returns all sales orders which have a responsible
salesman: