The SQL OR statement is used in similar fashion and the major difference compared to the SQL AND is that OR clause will return all rows satisfying any of the conditions listed in the WHERE clause.
If we want to select all Company having FirstName 'Jackson' or FirstName 'Santo' we need to use the following SQL statement:
SELECT * FROM Company
WHERE FirstName = Scott OR FirstName = 'Adam'
The result of this query will be the following:
FirstName | LastName | Email | DOB | Phone |
Scott | Armstrong | Armstrong.yahoo.com | 2/4/1968 | 887-676-2321 |
Adam | Red | red@himail.com | 4/4/1978 | 792 343-2422 |
You can combine AND and OR clauses anyway you want and you can use parentheses to define your logical expressions.
Here is an example of such a SQL query, selecting all Company with LastName 'Harry' and FirstName either 'Jackson' or 'Santo':
SELECT * FROM Company
WHERE (FirstName = Scott OR FirstName = 'Adam') AND LastName =’ Armstrong’
The result of the SQL expression above will be:
FirstName | LastName | Email | DOB | Phone |
Scott | Armstrong | Armstrong.yahoo.com | 2/4/1968 | 887-676-23 21 |
No comments:
Post a Comment