MySQL Where Condition Statement Introduction and operator summary _mysql

Source: Internet
Author: User
Tags logical operators

WHERE condition

Sometimes when you manipulate a database, you manipulate only conditionally restricted data, and you can add a WHERE clause to the SQL statement to specify the conditions for the operation of the data.

Grammar:

Copy Code code as follows:

SELECT column,... From Tb_name WHERE definition

The WHERE keyword is followed by a valid expression (definition) that represents the condition that the data record being manipulated must meet.
In addition to SELECT, the WHERE condition keyword can be used in any situation that the SQL syntax allows, such as update (update), delete (delete), and so on.
Example:

Copy Code code as follows:

SELECT * FROM user WHERE username = ' Jack '

This example specifies that the query condition is username equal to Jack's data.

Operator description in WHERE expression:

Parameter description:

operator Description
= Equals
!= Not equal to, some database systems also write <>
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
BETWEEN ... And ... Within a range, example: WHERE age BETWEEN 30
Not BETWEEN ... And ... Not within a certain range
In (item 1, item 2,...) Within the specified item, example: Where City in (' Beijing ', ' Shanghai ')
Not in (item 1, item 2,...) is not in the specified item
Like Search matches, often used in conjunction with pattern matching characters
Not like The anti-righteousness of like
Is NULL Null-value-judging character
is not NULL Non-null Judge character
Not, and, or Logical operators that represent no, and, or, for multiple logical connections.
Priority: not > and > OR
% pattern-matching character, representing any string, example: WHERE username like '%user '

Some WHERE examples

To specify a user based on user name query:

Copy Code code as follows:

SELECT * FROM user WHERE username = ' Jack '

Check the name and ID number of the user registered after 0 o'clock in the morning January 1, 2009:
Copy Code code as follows:

$regdate = Mktime (00, 00, 01, 01, 01, 2009);
SELECT uid,username from user WHERE regdate >= $regdate

Search for all users in the username with the word User:
Copy Code code as follows:

SELECT * FROM user WHERE username like '%user% '

Search for all users in the username that contain user or admin:
Copy Code code as follows:

SELECT * FROM user WHERE username like '%user% ' OR username like '%admin% '

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.