sql or statement

SQL OR statement is used in the case when you have 2 conditions and one of them is correct. OR Keyword is always used with WHERE Clause, whose role is to filter records.

By OR statement, you can extract data by applying more than one condition. OR operator extracts records if any of the OR conditions are true.

Related: 25 important examples of SQL where clause

But if both your conditions are correct, then you will get the data of both those fields for which you have set your conditions.

SQL OR Statement

To give you a better understanding, we have some easy examples of OR statements, after seeing which you will find out how to use OR in SQL.

Syntax
SELECT * FROM table
WHERE condition1 OR condition2;

In the example shown below, we have 2 conditions, where the address is ‘London’, the data for that field will come, OR where the address is “Sydney”, then the data for that field will come.

SELECT * FROM Employees
WHERE address='london' address='sydney';

Example 2

SELECT * FROM Employees
WHERE age='50' OR salary='5000';

SQL Where OR

Whenever you set your conditions inside SQL, you have to use WHERE Clause. Whether you are using “AND” operator whether “OR”, WHERE Clause is used with everyone.

SELECT * FROM Employees
WHERE state='california' AND state='florida';

Example 2

SELECT * FROM Employees
WHERE age='40' OR name='abc';

SQL AND OR

If you want to run both “AND” operator and “OR” operator together, then for that you have to write syntax something like this.

Related: 20 best examples of SQL like operator

In the following example, we have an address that is of London, but the names of 2 employees on whose base we want to extract this data.

SELECT * FROM Employees
WHERE address='london' AND (name='john' OR name='devid');

SQL Keywords

There are some keywords of SQL which are used most commonly. Let’s know what those keywords are and what they mean.

NoKeywordsDescription
1CREATEIt is used to create a database and table
2CREATE DATABASEIt is used to create a database only
3CREATE TABLEIt is used to create a table
4DELETEIt is used to delete record from the table
5DROPIt is used to delete a column, database, and table
6DROP COLUMNIt is used to delete a column in the table
7DROP TABLEIt is used to delete a table
8FOREIGN KEYIt is used to join two tables together
9JOINIt is used to join the tables
10UPDATEIt is used to update the record in the table
11ASCSet the result in ascending order
12BETWEENSelect the data inside a given value
13DESCSet the result in descending order
14DISTINCTSelect unique or different values
15INSERT INTOInserts new data into the table
16LIMITOnly shows as many records as you set the limit
17WHEREFilter records according to condition

Related: 16 most useful examples of SQL between and not between

Related: 13 simple examples of SQL sum and SQL count