Today we will learn about MySQL WHERE clause.
Why Used WHERE in MySQL:
When we want to search some data from a condition or any other criteria then we use MySQL WHERE clause. That means to search data from a condition, we use WHERE statement in MySQL.Rules of Writing WHERE clause in MySQL:
SELECT column_name,column_name FROM table_name WHERE column_name operator value;
So, look at the operator . We can use the following operator here:
= ---> Equal operator
> ---> Greater than operator
< ---> Less than operator
>= ---> Greater than or equal operator
<= ---> Less than or equal operator
<> ---> Not Equal operator
BETWEEN ---> To check two number using between condition
LIKE ---> To search anything like that word
IN ---> To check anything in the new relation or in new condition.
Example of MySQL WHERE clause:
In our second lecture of MySQL we have created a table and which is like this :Let Insert some data first to search as our specific condition:
INSERT INTO Student (ID, Name, Email, Address) VALUES ('1402011', 'Jhon', 'jhon@gmail.com', 'Delhi, India'); INSERT INTO Student (ID, Name, Email, Address) VALUES ('1402039', 'Nur', 'Nur@yahoo.com', 'Bagerhat, Bangladesh'); INSERT INTO Student (ID, Name, Email, Address) VALUES ('1402043', 'Musa', 'Musa@yahoo.com', 'Nepal'); INSERT INTO Student (ID, Name, Email, Address) VALUES ('1402044', 'XXX', 'xxx@yahoo.com', 'Nepal'); INSERT INTO Student (ID, Name, Email, Address) VALUES ('1402014', 'Roshan', 'roshan@gmail.com', 'Brazil'); INSERT INTO Student (ID, Name, Email, Address) VALUES ('1402020', 'Roshan', 'roshan_india@gmail.com', 'India'); INSERT INTO Student (ID, Name, Email, Address) VALUES ('1402030', 'Ronin', 'ronin@gmail.com', 'Brazil');
Ok, that's enough our Student table is like now:
Query 1: Select all from Student table of student name Roshan.
SELECT * FROM Student WHERE name = 'Roshan';
Query 2: Select all the names from Student table of student whose address is Brazil.
SELECT Name FROM Student WHERE Address = 'Brazil';
Query 3: Select all from Student table whose ID is less than or equal 1402030.
SELECT * FROM Student WHERE ID <= '1402030';
Query 4: Select all from Student table whose ID is between 1402030 and 1402014.
SELECT * FROM Student WHERE ID BETWEEN '1402030' AND '1402014';
Ok, thanks for staying with us. Run the code and see the output and get the exactly what you want. Please comment if you face any problem.
0 comments:
Post a Comment