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

Ads









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 Date in where clause     ... in Where clause. The given Query create table employee1 is used to create a table... | +-------+---------+------------+ 4 rows in set (0.00 sec) Query date where clause
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... is The select query used with where clause, which search the data
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
MySQL Case In Where Clause
MySQL Case In Where Clause       This example illustrates how to use case statement where clause...; Output: Using MySQL 'case' and 'where' clause: SELECT daysName
Mysql Where
Mysql Where       Mysql Where returns only those records from table which are specified in the WHERE Clause. The Where Clause restricts the select query and shows you only
Mysql where
for using where clause: The Query given below return the empname record from... Mysql where       Mysql Where is used to return the select records based
MySQL PHP Query delete
MySQL PHP Query delete       Mysql PHP Query delete is used to execute Mysql function ( ) delete query from a database table. MySQL PHP Query is used to delete the records
PHP WHERE clause example to fetch records from Database Table
query in PHP MYSQL example. PHP MYSQL WHERE Clause Syntax select * from... 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 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 Select Example
on the condition of nested select query specified in Where Clause. Understand...;  MySQL Nested Select is select query, that is nested inside... values(07,'Q','26000'); Query OK, 1 row affected (0.01 sec) mysql>
MySQL Nested Example
of nested select query specified in Where Clause. Understand with Example...; 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
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
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... a HQL where clause can be used. To achieve the solution of such problem
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...]... host :The host name where MySQL server is running. Default
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
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...;mysql_query($update, $con);   echo "Column <
SQL Aggregate Functions In Where Clause
SQL Aggregate Functions In Where Clause       SQL Aggregate Function In Where Clause return... specified in the 'Stu_Name'. In order to overcome, we use the WHERE clause
SQL Aggregate Functions Where Clause
SQL Aggregate Functions Where Clause       SQL Aggregate Functions Where Clause is used... Where Clause. To understand and grasp example we create a table 'Stu
MySQL Not In
' are not specified in the Where Clause. This is the efficient mean of retrieving... (0.00 sec) Query to use  Mysql not in : The Query below... Clause. mysql> UPDATE employee SET Empname='Girish' WHERE EmpId
Mysql date equal
in where clause. In this Query this show you the records from a table 'Employee' based on the date '2008-12-22' condition in where clause. mysql> select... condition specified in  where clause. Understand with Example The Tutorial
Mysql Date Filter
for comparison specified in Where Clause. Query for creating table employee1:- The Query...; comparison  to current date specified in where clause. mysql>... Mysql Date Filter      
MySQL Not Like
are not listed in the 'where clause'. Understand with Example The Tutorial...) 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
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
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 Not equal
based on the condition specified in the Where Clause. Query for creating table name... | +-------+----------+--------+------------+ 5 rows in set (0.00 sec) Query to use  MySQL not equal : The Query MySQL not equal returns only those records from table 'employee
Query to Test MySQL Performance
Query to Test MySQL Performance  Query to Test MySQL Performance
Mysql PHP Where
;select * from mytable where Empname like \"%h\""; mysql_query($sql... Mysql PHP Where       Mysql PHP Where is used to insert the records from database and print
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
specified in Where Clause. The mysql_fetch_array ( ) help you  to fetch... on the basis of condition specified in where clause. Understand with Example... values(07,'Q','26000'); Query OK, 1 row affected (0.01 sec) mysql> insert
select query in mysql
select query in mysql  Select query in mysql. Can anyone
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 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
on the basis of condition specified in where clause. Understand with Example... set in where clause.In this Query we modify or change the value of 'empname... Mysql Update      
MySQL PHP Query delete
MySQL PHP Query delete       Mysql PHP Query delete is used to execute Mysql function ( ) delete query from a database table. MySQL PHP Query is used to delete the records
insert query in mysql
insert query in mysql  insert query in mysql not working   [INSERT INTO Birthdays(firstname, lastname, birthday, group) VALUES('Sam','Smith','June','Junior
AND and OR Operators in MySQL Query
AND and OR Operators in MySQL Query  Hi, How to use the AND and OR Operators in MySQL Query? Thanks   Hi, We have a table with following... in following ways: select * from email where first_name='Deepak' OR first_name='Rajeev
range of dates in mysql query
range of dates in mysql query  How to select the range of dates in mysql ..when i have to select from between & and of date function?   SELECT * FROM MAAccounts WHERE updatedOn BETWEEN ? AND ? ORDER
mysql query for null value
mysql query for null value   What mysql query for null value i need to write to display message when no data in database? Please help.Thanks!   if(mysql_num_rows($data2) > 0){ //while loop goes here } else
PHP SQL Where
definition based on the condition specified in Where Clause. The PHP SQL Where allows you to update the field based on the condition specified in Where Clause... the PHP and MySQL. Once the connection is built successfully, the update query
HAVING Clause in JPQL (Java Persistence Query Language)
HAVING Clause in JPQL (Java Persistence Query Language... to use of HAVING Clause in jpql (Java Persistence Query Language). HAVING Clause... the query results of a GROUP BY in the SelectExpression. This clause is applied
PHP MySQL query
PHP MySQL query  I have 11 tables and have to do the CRUD operations keeping userid as a reference key
Function mysql_db_query() is deprecated
Function mysql_db_query() is deprecated  Hi, In latest version of PHP Function mysqldbquery() is deprecated. What could be the solution? Thanks
Function mysql_db_query() is deprecated
Function mysql_db_query() is deprecated  Hi, In latest version of PHP Function mysqldbquery() is deprecated. What could be the solution? Thanks

Ads