
- 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
Get all results using WHERE clause in MySQL?
To get all results using WHERE clause, you can use LIKE operator. We can also get all the results using “Select * from table_name”.
Let us first create a table:
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20) ); Query OK, 0 rows affected (0.56 sec)
Following is the query to insert records in the table using insert command:
mysql> insert into DemoTable(Name) values('Larry'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(Name) values('John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name) values('Bob'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name) values('Carol'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Name) values('Mike'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(Name) values('Sam'); Query OK, 1 row affected (0.11 sec)
Following is the query to display records from the table using select command:
mysql> select *from DemoTable;
This will produce the following output:
+----+-------+ | Id | Name | +----+-------+ | 1 | Larry | | 2 | John | | 3 | Bob | | 4 | Carol | | 5 | Chris | | 6 | David | | 7 | Mike | | 8 | Sam | +----+-------+ 8 rows in set (0.00 sec)
Query to get all results using WHERE clause:
mysql> select *from DemoTable where Name like '%';
This will produce the following output:
+----+-------+ | Id | Name | +----+-------+ | 1 | Larry | | 2 | John | | 3 | Bob | | 4 | Carol | | 5 | Chris | | 6 | David | | 7 | Mike | | 8 | Sam | +----+-------+ 8 rows in set (0.00 sec)
- Related Articles
- Get current year in MySQL WHERE clause?
- Using the entire expression in MySQL WHERE clause?
- Passing an array to a query using WHERE clause in MySQL?
- How to update multiple rows using single WHERE clause in MySQL?
- Update with multiple values in MySQL WHERE clause
- MySQL to Implementing OR operator in a WHERE clause?
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- Delete a specific record from a MySQL table by using AND in WHERE clause
- How to use MySQL VIEW with WHERE clause?
- How to use MySQL Date functions with WHERE clause?
- Can we use WHERE clause inside MySQL CASE statement?
- Can we fetch multiple values with MySQL WHERE Clause?
- Get a fixed number of results in descending order using a MySQL query
- How to add a where clause in a MySQL Insert statement?
- Get the returned record set order in MySQL IN clause?

Advertisements