Where clause with query in MySQL

Where clause with query in MySQL

Hi,

I want to learn the where clause in MySQL. Provide me the tutorials.

Thanks

View Answers

June 26, 2016 at 11:59 AM

Hi,

Here is the various example of where clause:

Suppose we have following table:

mysql> select * from email;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
| Rajeev     | Singh     | [email protected] |         500 |
| Dinesh     | Singh     | [email protected] |         200 |
| John       | T         | [email protected]   |         400 |
| Ishu       | roy       | NULL                 |         800 |
+------------+-----------+----------------------+-------------+

The you can use the following query to get one record:

select * from email where first_name='deepak';

Here is the output of query:

mysql> select * from email where first_name='deepak';
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
+------------+-----------+----------------------+-------------+
1 row in set (0.00 sec)

Following shows more uses of where clause:

mysql> select * from email where first_name='deepak' and last_name='Kumar';
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
+------------+-----------+----------------------+-------------+
1 row in set (0.00 sec)

mysql> select * from email where email_count>100;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Rajeev     | Singh     | [email protected] |         500 |
| Dinesh     | Singh     | [email protected] |         200 |
| John       | T         | [email protected]   |         400 |
| Ishu       | roy       | NULL                 |         800 |
+------------+-----------+----------------------+-------------+
4 rows in set (0.00 sec)

mysql> select * from email where email_count=100;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
+------------+-----------+----------------------+-------------+
1 row in set (0.00 sec)

mysql> select * from email where email_count between 100 and 200;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
| Dinesh     | Singh     | [email protected] |         200 |
+------------+-----------+----------------------+-------------+
2 rows in set (0.00 sec)

mysql> select * from email;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
| Rajeev     | Singh     | [email protected] |         500 |
| Dinesh     | Singh     | [email protected] |         200 |
| John       | T         | [email protected]   |         400 |
| Ishu       | roy       | NULL                 |         800 |
+------------+-----------+----------------------+-------------+
5 rows in set (0.00 sec)

mysql> select * from email where email is null;
+------------+-----------+-------+-------------+
| first_name | last_name | email | email_count |
+------------+-----------+-------+-------------+
| Ishu       | roy       | NULL  |         800 |
+------------+-----------+-------+-------------+
1 row in set (0.00 sec)

mysql>

Thanks









Related Tutorials/Questions & Answers:
Where clause with query in MySQL
Where clause with query in MySQL  Hi, I want to learn the where clause in MySQL. Provide me the tutorials. Thanks   Hi, Here is the various example of where clause: Suppose we have following table: mysql> select
Mysql Date in where clause
Mysql data in Where clause. The given Query create table employee1 is used... Mysql Date in where clause     ... | +-------+---------+------------+ 4 rows in set (0.00 sec) Query date where clause:- The Query below return
Advertisements
PHP SQL Query Where Clause
PHP SQL Query Where Clause     ... query with where clause. To understand how to display the result returned ...; is executed using mysql_query() method to select only those employees who have programmer
JPA Query with where clause and group by function
JPA Query with where clause and group by function  Any thing wrong in my JPA Query. TypedQuery<RaBdrRating> uQuery = (TypedQuery<...(charge),COUNT(activePackage) FROM User WHERE callType = :callType and startDate
HOW CN I USE WHERE AND BETWEEN CLAUSE SIMULTANEOUSLY... IN MYSQL
HOW CN I USE WHERE AND BETWEEN CLAUSE SIMULTANEOUSLY... IN MYSQL  sir, how can i use WHERE and BETWEEN clause simultaneously..? my tables details... between two dates whose expfor_id = 1 my query is SELECT * FROM expenditures
Where clause
Where clause  I have doubt in Where clause .. i got a Employid from...; The WHERE clause is used to filter records.It is used to extract only those records that fulfill a specified criterion. SQL WHERE Syntax: SELECT column
Where Clause in SQL
Where Clause in SQL       The Where clause in SQL query is used  with the SELECT keyword... of the above query is The select query used with where clause, which search
where clause in select statement
where clause in select statement  In Mysql,I write the following query: select * from emp where designation = "MANAGER" But the actual value in the table is "manager" Will the above query retrieve any records? According to me
Where and Having clause
Where and Having clause   hii, What is the difference between where and having clause?   hello,ADS_TO_REPLACE_1 WHERE clause is used... Function and is used after GROUP BY clause in the query
MySQL Case In Where Clause
MySQL Case In Where Clause       This example illustrates how to use case statement where clause... 'case' and 'where' clause: SELECT daysName, CASE daysName    WHEN
Mysql Where
Clause. The Where Clause restricts the select query and shows you only... (0.01 sec) Query for using where clause:ADS_TO_REPLACE_4... Mysql Where      
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
BY function in a query. WHERE Clause can be used for specifying the search...What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?  What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?   Hi
Mysql where
| +-------+---------+--------+ 9 rows in set (0.01 sec) Query for using where clause... Mysql where       Mysql Where is used to return the select records based
PHP WHERE clause example to fetch records from Database Table
query in PHP MYSQL example. PHP MYSQL WHERE Clause SyntaxADS_TO_REPLACE_1... different actions in MYSQL Database Tables. PHP WHERE Clause is one of them. We can use the WHERE clause in PHP & MYSQL to  add, edit or delete
MySQL PHP Query delete
_error()); $sql="delete from mytable where empid= ".$id; mysql_query... MySQL PHP Query delete       Mysql PHP Query delete is used to execute Mysql function
Mysql Where Statement
Mysql Where Statement       Mysql Where Statement is useful when we want to return the records on the basis of specified condition in Where Clause. The Where Clause restricts
MySQL Nested Example
of nested select query specified in Where Clause. Understand with ExampleADS...; MySQL Nested Select is select query, that is nested inside the select, update and delete query  based on the condition specified in a Where Clause
MySQL Nested Select Example
on the condition of nested select query specified in Where Clause. Understand...;  MySQL Nested Select is select query, that is nested inside...) mysql> insert into MyTable values(07,'Q','26000'); Query OK, 1 row affected
SQL Backup query with where statement
SQL Backup query with where statement       SQL Backup query with where statement  is used to construct a backup table using where clause. The Where Clause
HQL Where Clause Example
HQL Where Clause Example       Where Clause is used to limit the results returned from... lngInsuranceId='1'ADS_TO_REPLACE_1 Where Clause can be used with or without Select
Hibernate WHERE Clause
Hibernate WHERE Clause In this tutorial you will learn how to use HQL where clause. Use of WHERE clause in hibernate is as same as it used in SQL... will demonstrate you how a HQL where clause can be used. To achieve the solution
Explain the use of the ‘LIKE’ keyword used in the WHERE clause?
Explain the use of the ?LIKE? keyword used in the WHERE clause?   Explain the use of the ?LIKE? keyword used in the WHERE clause
Explain the use of the ‘LIKE’ keyword used in the WHERE clause?
Explain the use of the ?LIKE? keyword used in the WHERE clause?   Explain the use of the ?LIKE? keyword used in the WHERE clause
Using WHERE Clause in JDBC
Using WHERE Clause in JDBC    Where... conditions. It allows to filter the data from a table, a WHERE clause can be added to the SELECT statement. The WHERE clause searches the specific results
JDBC: WHERE Clause Example
. WHERE Clause : MySql Where Clause is used to write some condition and data...JDBC: WHERE Clause Example In this section, we will discuss how to use WHERE.... port : The port number where MySQL is listening for connection. Default
SQL Aggregate Functions Where Clause
SQL Aggregate Functions Where Clause       SQL Aggregate Functions Where Clause return you the aggregate sum of the records based on the condition specified in Where Clause condition
Php Sql Where
Php Sql Where This example illustrates how to use the WHERE clause in the UPDATE query in PHP. In this example we create a UPDATE query with WHERE clause...;WHERE emp_id = 1";   mysql_query($update, $con
SQL Aggregate Functions In Where Clause
SQL Aggregate Functions In Where Clause       SQL Aggregate Function In Where Clause return... in the 'Stu_Name'. In order to overcome, we use the WHERE clause. The Syntax
SQL Aggregate Functions Where Clause
SQL Aggregate Functions Where Clause       SQL Aggregate Functions Where Clause is used... Aggregate Function Where Clause. To understand and grasp example we create a table
What is the difference between IN and BETWEEN, that are used inside a WHERE clause?
What is the difference between IN and BETWEEN, that are used inside a WHERE clause?  What is the difference between IN and BETWEEN, that are used inside a WHERE clause?   Hi, The BETWEEN clause is used to fetch a range
SQL Backup query with where statement
SQL Backup query with where statement       SQL Backup query with where statement  is used to construct a backup table using where clause. The Where Clause
Mysql date equal
condition specified in  where clause. Understand with ExampleADS... only those records from employee table as condition specified in where clause... '2008-12-22' condition in where clause. mysql> select * from employees
MySQL Not In
' are not specified in the Where Clause. This is the efficient mean of retrieving...) Query to use  Mysql not in :ADS_TO_REPLACE_4 The Query below would help you to update records which are not in the EmpId '2,3,4,5' of Where Clause
MySQL Not Like
are not listed in the 'where clause'. Understand with ExampleADS_TO_REPLACE_1...) Query to use  Mysql not like : The Query below is used to return those records which are not specified in Where Clause. In this example table return all
php MySQL order by clause
php MySQL order by clause:       In SQL generally we use three clauses, select ,from, and where. ...); $result=mysql_query("select * from student order by name asc"); while
Mysql Date Filter
Mysql Date Filter       Mysql Date Filter is used to find the date portion of the timestamp for comparison specified in Where Clause. Query for creating table employee1:-ADS
how to use comma separated value list in the where clause oracle
how to use comma separated value list in the where clause oracle  Hi, how to use comma separated value list in the where clause oracle Thanks   HI, Following code will help you: select * from employee where id
Mysql PHP Where
Mysql PHP Where       Mysql PHP Where is used to insert the records from database and print..._TO_REPLACE_1 The Tutorial illustrate an example from 'Mysql PHP Where'. To understand
MySQL Not equal
based on the condition specified in the Where Clause. Query for creating table name...) Query to use  MySQL not equal : The Query MySQL not equal... MySQL Not equal      
Query to Test MySQL Performance
Query to Test MySQL Performance  Query to Test MySQL Performance
mysql query
mysql query  how do transfer into the excel data to my sql  ... with ("jdbc:odbc:excel"). Execute query "select name, address from [Sheet1$]". Here... the mysql connection in your php and store the list values inside the mysql
MySQL PHP Search
table 'mytable' on the basis of condition specified in Where Clause. The mysql... where Empname=\"girish\""; mysql_query($sql,$link) or exit("... on the basis of condition specified in where clause. Understand with ExampleADS
select query in mysql
select query in mysql  Select query in mysql. Can anyone
mysql query
mysql query  I have two tables namely sms and bdpaidbribe. I want to insert a column "Message" of sms table into "caddiinfo" column of bdpaidbribe table. and whenever the Message is inserted into sms table it should automatically
Mysql Update
to the column on the basis of condition specified in where clause. Understand... of condition set in where clause.In this Query we modify or change the value... Mysql Update      
Mysql Update
Mysql Update       Mysql Update is used to modify the table and set a new value to the column on the basis of condition specified in where clause. Understand with ExampleADS
MySQL PHP Query delete
()); $sql="delete from mytable where empid= ".$id; mysql_query($sql... MySQL PHP Query delete       Mysql PHP Query delete is used to execute Mysql function
Explain the use of the ?LIKE? keyword used in the WHERE clause? Explain wildcard characters in SQL.
Explain the use of the ?LIKE? keyword used in the WHERE clause? Explain wildcard characters in SQL.  Explain the use of the ?LIKE? keyword used in the WHERE clause? Explain wildcard characters in SQL
Explain the use of the ‘LIKE’ keyword used in the WHERE clause? Explain wildcard characters in SQL.
Explain the use of the ?LIKE? keyword used in the WHERE clause? Explain wildcard characters in SQL.  Explain the use of the ?LIKE? keyword used in the WHERE clause? Explain wildcard characters in SQL
mysql query - WebSevices
mysql query  From your answer for my last post "SELECT * FROM roseindia WHERE age BETWEEN '20' AND '30' " If the age field... we compare with from and to ages?.  Hi... U May create your query

Ads