Leilin Peng Share: MySQL WHERE clause

  We know that to read the data using SQL SELECT statement from the MySQL table.

  To conditionally select data from the table, can be added to the WHERE clause of a SELECT statement.

  grammar

  The following is the general syntax of SQL SELECT statement using the WHERE clause to read data from the data table:

  SELECT field1, field2,...fieldN FROM table_name1, table_name2...

  [WHERE condition1 [AND [OR]] condition2.....

  You can query using one or more tables, use a comma between tables, segmentation, and use the WHERE clause to set the search criteria.

  You can specify any condition in the WHERE clause.

  You can use AND or OR specify one or more conditions.

  WHERE clause can also be used in a SQL DELETE or UPDATE command.

  Conditions similar to the WHERE clause if the programming language to read the specified data according to the field values ​​in the table MySQL.

  The following is a list of operators, it can be used in the WHERE clause.

  Examples in the following table assuming that A is 10, B 20

  Operator Description Example

  = Equal sign, two detection values ​​are equal if they are equal Returns true (A = B) returns false.

  <>,! = Not equal, detected two values ​​are equal, if not equal Returns true (A! = B) returns true.

  > Greater than the number, whether the detected value is greater than the value of the left side of the right to the left if the value is greater than the value of the right returns true (A> B) returns false.

  <Less, the detected value is smaller than the value on the right to the left if the value is less than the value of the right side of the left Return true true (A <B).

  > = Greater than or equal to number, detecting whether a value greater than or equal to the left of the right, if the return value is greater than or equal to the left to the right of the true (A> = B) returns false.

  <= Less than or equal number, whether the detected value is less than or equal to the value of the left side of the right, if the return value is less than or equal to the left to the right of true (A <= B) returns true.

  If we want to read the specified data in MySQL data tables, WHERE clause is very useful.

  As a condition of using the primary key to the WHERE clause of the query is very fast.

  If given the absence of any matching records in the table, then the query does not return any data.

  Reading data from the command prompt

  We will use the WHERE clause in the SQL SELECT statement to read data in MySQL data tables codercto_tbl:

  Examples

  The following examples will read all records in the table codercto_author codercto_tbl Sanjay field values ​​of:

  SQL SELECT WHERE clause

  SELECT * from codercto_tbl WHERE codercto_author = 'AGRICULTURAL tutorial code';

  MySQL string comparison WHERE clause is not case sensitive. You can use the BINARY keyword to set the WHERE clause string comparisons are case-sensitive.

  Following examples:

  BINARY keyword

  mysql> SELECT * from codercto_tbl WHERE BINARY codercto_author='codercto.com'; Empty set (0.01 sec) mysql> SELECT * from codercto_tbl WHERE BINARY codercto_author='CODERCTO.COM'; +-----------+---------------+---------------+-----------------+ | codercto_id | codercto_title | codercto_author | submission_date | +-----------+---------------+---------------+-----------------+ | 3 | JAVA 教程 | CODERCTO.COM | 2016-05-06 | | 4 | 学习 Python | CODERCTO.COM | 2016-03-06 | +-----------+---------------+---------------+-----------------+ 2 rows in set (0.01 sec)

  Example BINARY keyword used, is case-sensitive, so codercto_author = 'codercto.com' query criteria is no data.

  Use PHP script to read data

  You can use PHP function mysqli_query () and put on the same SQL SELECT command WHERE clause to retrieve data.

  This function is used to execute SQL command, and then () outputs the data in all queries by PHP function mysqli_fetch_array.

  Examples

  The following examples from the table codercto_tbl codercto_author Returns the field value records CODERCTO.COM:

  MySQL WHERE clause tests:

   Tutorial MySQL WHERE clause farming code test

'; echo ' '; while($row = mysqli_fetch_array($retval, MYSQL_ASSOC)) { echo " ". " ". " ". " ". ""; } echo '

Course ID title Author Date of submission
{$row['codercto_id']} {$row['codercto_title']} {$row['codercto_author']} {$row['submission_date']}

'; // release the memory mysqli_free_result ($ retval); mysqli_close ($ conn);?>

 

  Click to see all MySQL Tutorial Articles: https://www.codercto.com/courses/l/30.html (edit: Leilin Peng Source: network intrusion deleted)

Guess you like

Origin www.cnblogs.com/pengpeng1208/p/10978606.html