In this article we will see "How to SELECT data FROM a Table based on conditions in MySql" and "MySql SELECT WHERE query syntax with example".

"WHERE" query syntax

"WHERE" is used to SELECT conditional data FROM a Table in MySql, the syntax is as follow.


SELECT column1, column2, ...
FROM tableName
WHERE condition;

"WHERE" query on test field example

"WHERE" can be used to SELECT conditional data FROM a Table in MySql, if condition is based on a text field the value must be enclosed within '', as shown in the example below.


/* WHERE data */
SELECT * from testTable WHERE name = 'techburps';

Output: Output will be something like this:


+------+--------------------+-----------+
| id   | email              | name      |
+------+--------------------+-----------+
|    1 | info@techburps.com | techburps |
|    2 | NULL               | techburps |
+------+--------------------+-----------+
2 rows in set (0.00 sec)


"WHERE" query on numeric field example

"WHERE" can be used to SELECT conditional data FROM a Table in MySql, if condition is based on a numeric field the value should be supplied without any quotes, as shown in the example below.


/* WHERE data */
SELECT * from testTable WHERE id = 1;

Output: Output will be something like this:


+------+--------------------+-----------+
| id   | email              | name      |
+------+--------------------+-----------+
|    1 | info@techburps.com | techburps |
+------+--------------------+-----------+
1 row in set (0.00 sec)



In this article we have seen "How to SELECT data FROM a Table based on conditions in MySql", in upcoming articles we will see more about Mysql syntax and queries with example.
  • By Techburps.com
  • Oct 17, 2017
  • MySql