What is this Site!!

All about Real time requirements in Orale Stay Tune!!
Showing posts with label Combining Search Conditions. Show all posts
Showing posts with label Combining Search Conditions. Show all posts

Friday, February 8, 2008

SQL Server


>>Previous>>


Combining Search Conditions


As the previous example demonstrates, one can combine search conditions. But one need to be cautious when combining search conditions if one isn't familiar with Boolean logic: Don't confuse the AND and OR conditions.

Suppose someone say, "Get me a list of all our authors from Utah and Texas." One knows what one want.

But if one write the query as---


SELECT au_fname, au_lname, phone, au_id
FROM authors
WHERE state LIKE 'ut' AND state LIKE 'tx'


The query will not return any data because it asked for all authors who live in both Utah and Texas. The result you want is data that meets both conditions, authors who live in either Utah or Texas.

Instead, use this query:


SELECT au_fname, au_lname, phone, au_id
FROM authors
WHERE state LIKE 'ut' OR state LIKE 'tx'


Note that one needs to repeat the search condition. One can't write WHERE state LIKE 'ut' OR 'tx' because SQL Server expects a complete search condition on either side of the OR.



>>>Next>>>