Where clause with query in MySQL

Ads
 

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
Where and Having clause
Where and Having clause   hii, What is the difference between where and having clause?   hello, WHERE clause is used to impose... 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...; 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 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
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
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
in a query. WHERE Clause can be used for specifying the search criteria in SELECT...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
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 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
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>
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' Where Clause can be used with or without Select Clause. Here
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
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
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
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 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

Ads