Several common SQL query statements in the sorted Database

Source: Internet
Author: User

1. The simplest single-condition query, where specifies the query conditions.

Select messagetype, messagename from t_sr_message where messagename = 'manage'

The following lists several query conditions, not all:

2. query groups

Select superno, typename from t_sr_messagetype group by superno, typename having typename <'20140901'
// Records of the superno and typenamecolumns are returned Based on the superno and typename groups, and the condition typename <200 must be met.

 

 

3. Sort query select * From t_sr_messagetype order by DESC

Order by can specify how the query results are sorted. Desc indicates reverse order, ASC indicates order

4. Convert and query the select userid user number, username user name, And userpwd user password from userinfo

The query result is as follows:

User ID User Name User Password
1 Sword 123456
2 Niuniu 654321

5. Calculate and query select logincount + exitcount from userinfo

6. Equivalent multi-Table query
An equivalent multi-Table query queries the associated data of multiple data tables according to the equivalent conditions. Some fields of the associated data tables must have the same data type, width, and value range: select. name, B. typename from a, B where. id = B. ID

Query records with the same IDS as those in table B.
Non-equivalent multi-table queries are similar.

7. A nested query with 'in': select news. newtitle from news where news. userid in (select userid from userinfo where
Username <> 'sword ')

Query records of the newtitle field in the news table
The query results must meet the following conditions: first, query all the userids whose username is not the same as 'sword' in the userinfo table, and then obtain all the news of the userid in the previous userid in the news table. newtitle record.

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.