mysql how to add a WHERE clause in the SELECT statement

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags data how to mysql mysql tutorial network network programming operator operators

To select the data that matches the specified criteria, add the WHERE clause to the SELECT statement.

WHERE clause

To select the data that matches the specified criteria, add the WHERE clause to the SELECT statement.

Syntax SELECT column FROM table WHERE column operator value

The following operators can be used with the WHERE clause:

Operator Description = equal! = Not equal> greater than <less than> = greater than or equal to <= less than or equal to BETWEEN LIKE search within a range inclusive

Note: SQL statements are case insensitive. WHERE and where equivalent.

In order for PHP to execute the above statement, we must use the mysql_query () function. This function is used to send queries and commands to SQL connections.

example

The following example selects all the rows of FirstName = 'Peter' from the "Person" table:

<? php $ con = mysql_connect ("localhost", "peter", "abc123"); if ($ con) {die ('Could not connect:'. mysql_error ());} mysql_select_db ("my_db", $ ; $ result = mysql_query ("SELECT * FROM person WHERE FirstName = 'Peter'"); while ($ row = mysql_fetch_array ($ result)) {echo $ row ['FirstName']. "". $ row [ LastName ']; echo "<br />";}?>

Output of the above code:

Peter Griffin
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.