SQL statements learn to accumulate and manipulate data

Source: Internet
Author: User

operation of the data

    • Select

Take the first five data in the table

Top 5 from table_name

Take the first 50% of the data in the table

Top percent from table_name
    • ORDER BY:

Default ordering; desc indicates descending order (reverse order)

Returns the only distinct value for a column in a table:

DISTINCT column_name from table_name
    • Like:
      • >%

    Fuzzy query, query condition starts with K

 like ' K% '

Fuzzy query, the query condition is ending with X

 like '%x '
      • Wildcard characters _

   _ Instead of one character

SELECT * from Persons WHERE FirstName like ' _eorge '
      • [Charlist]

    • Between...and

Queries data that ranges between two values. Applies to numeric types, text types, and date types. Different databases, for the processing of boundary values, some databases get the inclusion of two boundaries or a boundary value, and some databases get not including the boundary values.

    • JOIN

  SELECT col1,col2,col3 from TableA INNER joins TableB on tablea.a_id = tableb.b_id

Different join types differ:

      1.   JOIN: Returns a row if there is at least one match in the table, no row is returned if no match (INNER join and join are the same)
      2.   Left JOIN: Returns all rows from the table, even if there are no matches in the right table. Returns all rows of the left table that match the right table, returns the relevant value of the right table to query, and the corresponding column value is empty if the right table does not match
      3.   Right JOIN: Returns all rows from the correct table, even if there is no match in the left table. Ditto.
      4.   Full JOIN: Returns a row as long as there is a match in one of the tables. Collection of left join and right join
    • UNION
Combine result sets of two or more SELECT statements

    • Insert

Insert a new row into the table


VALUES (Val1,val2,val3,..., valn)
Insert new row, specify column to insert new value

Or

INSERT INTO table_name SET VALUES
(Val1,val2,val3,..., Valn)

Insert New row

    • Update

Updating existing data in a table

    • Delete

Delete some data from the table, where the user name begins with Vuser_:

Delete from ttyz_users where user_name like '%vuser_% '
Delete from table_name where column_name like '%xxx% '

Encounter a problem: error-27796:failed to connect to server "10.133.96.35:80": [10061] Connection refused since the number of virtual users has been set to 1000, it has not been able to solve

SQL statements learn to accumulate and manipulate data

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.