Krivalar Tutorials 
Krivalar Tutorials



SQL AND operator - join condition in DBMS

<< Previous - SQL GROUP BY

Next - SQL OR OPERATOR >>






SQL AND, OR, & NOT operators are used to filter the record from the table in the database. The AND & OR operators are called as conjunctive operators. These operators can be always combined in the WHERE clause.

AND Operator

By using AND operator, more than one conditions are specified that are separated by AND keyword. If all conditions areTRUE then only it would retrieve the record from table.

Syntax


SELECT * FROM table-name
WHERE condition 1 AND condition 2 AND .......condition N ;

Example of AND

Below is the example student table in collegedb.


mysql> SELECT * FROM student ;
+--------+---------+------+-----------+
| RollNo | Name    | Age  | City      |
+--------+---------+------+-----------+
|      1 | Aruna   |   18 | Chennai   |
|      2 | Varun   |   19 | Bangalore |
|      3 | Ara     |   19 | Kerala    |
|      4 | Markdin |   18 | Mumbai    |
|      5 | Kannan  |   20 | Kerala    |
|      6 | Kanika  |   18 | Chennai   |
|      7 | Jose    |   19 | Kerala    |
+--------+---------+------+-----------+
7 rows in set (0.11 sec)



Following SQL statement selects the records only if the City = 'Chennai' and Age = 18.

mysql> SELECT * FROM student WHERE City = 'Chennai' AND Age = 18;
+--------+--------+------+---------+
| RollNo | Name   | Age  | City    |
+--------+--------+------+---------+
|      1 | Aruna  |   18 | Chennai |
|      6 | Kanika |   18 | Chennai |
+--------+--------+------+---------+
2 rows in set (0.03 sec)

<<Previous - SQL GROUP BY

Next - SQL OR OPERATOR >>









Searching using Binary Search Tree