
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Can I use two where clauses like “SELECT * FROM table WHERE condition1 and condition2” in MySQL?
Yes, you need to use AND or OR operator. The syntax is as follows −
select *from yourTableName where yourColumnName1=yourValue AND yourColumnName=yourValue';
For AND condition, both conditions must be true otherwise you will get an empty set.
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table WhereDemo -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.56 sec)
Now you can insert some records in the table using insert command. The query is as follows −
mysql> insert into WhereDemo values(101,'Maxwell'); Query OK, 1 row affected (0.14 sec) mysql> insert into WhereDemo values(110,'David'); Query OK, 1 row affected (0.21 sec) mysql> insert into WhereDemo values(1000,'Carol'); Query OK, 1 row affected (0.18 sec) mysql> insert into WhereDemo values(1100,'Bob'); Query OK, 1 row affected (0.47 sec) mysql> insert into WhereDemo values(115,'Sam'); Query OK, 1 row affected (0.23 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from WhereDemo;
The following is the output −
+------+---------+ | Id | Name | +------+---------+ | 101 | Maxwell | | 110 | David | | 1000 | Carol | | 1100 | Bob | | 115 | Sam | +------+---------+ 5 rows in set (0.00 sec)
Here is the query to select all records from the table with more than one condition −
mysql> select *from WhereDemo where Id=1100 AND Name='Bob';
The following is the output −
+------+------+ | Id | Name | +------+------+ | 1100 | Bob | +------+------+ 1 row in set (0.00 sec)
- Related Articles
- Using LIKE for two where clauses in MySQL?
- Select from table where value does not exist with MySQL?
- How can I use SPACE() function with MySQL WHERE clause?
- How to select from table where conditions are set for id and name in MySQL?
- How can we use two columns with MySQL WHERE clause?
- How to select data from a table where the table name has blank spaces in MYSQL?
- How do I select data from one table only where column values from that table match the column values of another table in MySQL?
- Update only a single value from a MySQL table where select from same table ordered in descending order?
- SELECT WHERE IN null in MySQL?
- How can I select only those rows where first digit is a number from 0 to 9 in MySQL?
- Can we use WHERE, AND & OR in a single MySQL query?
- MySQL Select where values IN List string?
- MySQL select query with multiple WHERE?
- Can we use WHERE clause inside MySQL CASE statement?
- SELECT where row value contains string in MySQL?

Advertisements