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]roseindia.net |         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
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
Advertisements
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 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
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
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
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 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 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
Query to Test MySQL Performance
Query to Test MySQL Performance  Query to Test MySQL Performance
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
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
select query in mysql
select query in mysql  Select query in mysql. Can anyone

Ads