MySQL Database common statements 2

Source: Internet
Author: User

On the collation of common MySQL statements, the previous article involved DDL, DML, and some simple query statements.

1:mysql Paging Query

SELECT * FROM table_name limit 5, 10; From the subscript for 5 element query, query 10 records, note: MySQL subscript starting from 0

2: Correlation Query

Select A.id,a.name,b.id,b.name from table_name A, table_name b where a.id=b.id; Table A and Table B correlate queries with field IDs

3: Compare the following statement

SELECT * FROM table_name where column_name=column_value; Querying table data based on the value of a field

SELECT * FROM table_name where column in (Column_value1,column_value2,.....); Use in to query data when there are multiple values

SELECT * FROM table_name where column in (select Column_value from table_name); Advanced subquery to query the result set of a table as a conditional query

4: Issues to be noted in building tables

Not null: A field with a non-null constraint has this constraint, and when a value is inserted into a table, it cannot be empty.

Default ' m ': defaults to ' m ' after a table is established

Primary key: Set a PRIMARY KEY constraint, which is to set a marker for a field, Auto_increment: Auto increment step is 1

Is null: When the Judge field is empty, use is instead of =

5: Fuzzy query like _%

SELECT * FROM table_name where name is like%user_;

%: Represents any character _: represents a character

6: > < = = = <> <= >= logic-judged symbols, which are often used in combination with any

7:exists whether a field exists in the table, the example is as follows

SELECT * from emp e where empno>0 and exists (SELECT ' x ' from Dept D where E.deptno=d.deptno and d.loc= ' Beijing ');

MySQL Database common statements 2

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.