AND / OR / NOT

1. AND:  
SELECT * FROM People WHERE LName='Smothers' AND Category=2

The SQL Statement above will retrieve

ALL fields: SELECT *

From the table named People: FROM People

With the requirement that the LName is Smothers and the category=2: WHERE LName='Smothers' AND Category=2

If this is the original table
People
FNameLNameCategory
JohnSmith1
AlJones2
FredSmothers2
JimSmothers1


Your recordset returned would be this:
People
FNameLNameCategory
FredSmothers2


2. OR:  
SELECT * FROM People WHERE LName='Smothers' OR Category=2

The SQL Statement above will retrieve

ALL fields: SELECT *

From the table named People: FROM People

With the requirement that the LName is Smothers or the category is 2: WHERE LName='Smothers' OR Category=2

If this is the original table
People
FNameLNameCategory
JohnSmith1
AlJones2
FredSmothers2
JimSmothers1


Your recordset returned would be this:
People
FNameLNameCategory
FredSmothers2
JimSmothers1
AlJones2


3. NOT:  
SELECT * FROM People WHERE LName NOT LIKE 'SM%'

The SQL Statement above will retrieve

ALL fields: SELECT *

From the table named People: FROM People

With the requirement that the LName does not start with Sm: WHERE LName NOT LIKE 'Sm%'

If this is the original table
People
FNameLNameCategory
JohnSmith1
AlJones2
FredSmothers2
JimSmothers1


Your recordset returned would be this:
People
FNameLNameCategory
AlJones2





Come learn HTML or Classic ASP in Honolulu, Hawaii!

HOME | SQL Tutorials | XML Tutorials | OKIWEB | EMAIL ME | ASP Alliance