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.
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.
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');
There are some keywords of SQL which are used most commonly. Let’s know what those keywords are and what they mean.
|1||CREATE||It is used to create a database and table|
|2||CREATE DATABASE||It is used to create a database only|
|3||CREATE TABLE||It is used to create a table|
|4||DELETE||It is used to delete record from the table|
|5||DROP||It is used to delete a column, database, and table|
|6||DROP COLUMN||It is used to delete a column in the table|
|7||DROP TABLE||It is used to delete a table|
|8||FOREIGN KEY||It is used to join two tables together|
|9||JOIN||It is used to join the tables|
|10||UPDATE||It is used to update the record in the table|
|11||ASC||Set the result in ascending order|
|12||BETWEEN||Select the data inside a given value|
|13||DESC||Set the result in descending order|
|14||DISTINCT||Select unique or different values|
|15||INSERT INTO||Inserts new data into the table|
|16||LIMIT||Only shows as many records as you set the limit|
|17||WHERE||Filter records according to condition|