What is an operator?
We will discuss about the SQL EXISTS operators , and use of it. But , before learning SQL operators , we ought to know about the basic of operators.An operator, in computer programming, is a symbol that usually represents an action or process. Expression is incomplete without an operator.operator works as a conjunction between operands .operators and operand makes a complete expression.
Ex:1) 2+3=5: 2,3 are operand : ‘+’ is operator
2)Following code mentioned below has a if statement followed by some statements in it . “>=” is a comparison operator , and in ‘b+=1’ “+” is the arithmetic operator.
SQL Logical Operators
Following are the logical operators in SQL:
|ALL||Condition is True if all the subquery matches the condition|
|AND||Result is True if all the condition separated by AND is true|
|ANY||Result is True if any of the subquery matches the condition|
|BETWEEN||BETWEEN operator is used to decide a range . If the operand lies within the range of condition that o/p is True.|
|EXIST||Following operator results True if the subquery return one or more records|
|IN||Result is True if the operand lies withing the range of list of expressions or exactly matches the expression.|
|LIKE||Operator is used when a operand is forced to match a expression. It executes when the condition matches.|
|OR||Results True when the operand matches either of the condition separated by OR operator|
|NOT||This operator is same as of ‘LIKE’ but its functions differs from LIKE .Dislplay a record if conditon is “NOT TRUE”.|
SQL EXISTS Operator
SQL Exists Operator is a Logical operator in SQL procedural programming language. Exists Operator is used to test the existence of any value/record in a subquery. EXISTS operator return type is -‘true’ if it follows the condition.
Let us look at some examples and understand the concept of EXIST Operator in SQL:-
Demo table 1 : Products
Demo table 2: Area
FROM Area /*Table 2*/
WHERE EXISTS (SELECT Prodcut FROM Products WHERE Code = harsh.Code AND Price < 300);
The following SQL statement results true and will broadcast all the values with Price <300
Description: Code attributes are present in both the tables . There are 2 items in the table with Price <300, The following code (#666,#665 are matched to table ‘2’ and there locations are printed.
Location: West ,East
Example 2 :
FROM Area /*Table 2*/
WHERE EXISTS (SELECT Product FROM Products WHERE Code = harsh.Code AND ID >2);
The following SQL statement results true and will broadcast all the values with ID >2.
Hope that you liked this article , for any doubts and queries , drop your questions in the comment section down below.