Proficient in SQL structured queries---Learn NOTE 3

Source: Internet
Author: User
Tags dname

  1. The order of the Chinese characters is sorted by the first letter. there is a price to pay for using DISTINCT; because you want to remove duplicate values, you must sort the result relationships, the same tuples are arranged together, and the tuples are grouped in such a way that the duplicate values are removed, which is even more time-consuming than the query itself.

  2. use the '*' wildcard with caution when you do not need to query all the columns, try to use the single-column query or the multicolumn query described earlier, so as not to consume too much resources.

  3. The order By clause must be placed at the end of all clauses, ASC ( ascending sort ) by default ;

    to use 1,2,3 ... To sort,1,2,3... Represents the order of the columns behind the SELECT.

    For example:

    SELECT column1,column2,column3 from dual ORDER by 1,2;

    SELECT column1,column2,column3 from dual ORDER by Column1,column2;

    3.1, if the column required by the order is not in the range selected by the SELECT statement, it is obviously not feasible to use the column ordinal. You can then mix the column alias with the serial number to solve the problem.

    3.2, the sorting of uppercase andlowercase characters, the general database management system thinks the two are equivalent.

  4. The WHERE clause gets The result set returned by the FROM clause and filters The result set by applying the search criteria defined in the WHERE clause. Each row that returns a result from the FROM clause is checked against the search criteria, and the return of the condition is met, and the non-conforming result is removed.

  5. A null value participates in any comparison operation, and the result is treated as FALSE, that is, either " NULL <>

"Null=" , the result is FALSE ; to NULL a worthwhile operation can only be: " is NULL "or

" null null participate in the aggregation operation, except count (*) null null and

650) this.width=650; "Width=" 661 "height=" 259 "title=" 1.jpg "style=" WIDTH:573PX;HEIGHT:259PX; "alt=" Wkiom1tzrtotlwacaahlyxf9ng8490.jpg "src=" Http://s3.51cto.com/wyfs02/M01/5A/03/wKiom1TzrTOTLwacAAHlyxf9NG8490.jpg "/>

650) this.width=650; "width=" 388 "height=" 277 "title=" 2.jpg "style=" width:364px;height:252px; "alt=" Wkiol1tzrmss0nsuaaiojjhqvwq883.jpg "src=" http://s3.51cto.com/wyfs02/M02/59/FF/ Wkiol1tzrmss0nsuaaiojjhqvwq883.jpg "/>650" this.width=650; "width=" 415 "height=" 192 "title=" 3.jpg "style=" width : 365px;height:244px;float:right; "alt=" wkiom1tzrxhiizydaaf6j5gqt0a324.jpg "src=" http://s3.51cto.com/wyfs02/M02/ 5a/03/wkiom1tzrxhiizydaaf6j5gqt0a324.jpg "/>


  1. logical Operator " the priority of and "is higher than"OR", in order to implement simultaneous operation, parentheses are applied.

    For example: the following The result of SQL execution is the information of all teachers who pay more than the computer and biological classes .

    SELECT Tname, Dname, SAL

    From TEACHER

    WHERE (dname = ' computer ' OR dname = ' creature ')

    and SAL > 1000

    ORDER by SAL;

    If there is no parenthesis, then the query is the computer class pay more than all the teacher's information

  2. In compared to or, in has the following advantages:

  3. when many conditions are chosen, the use of The in operator is easy to use, just list them in parentheses with a comma interval.

  4. Use in operator, which can be followed by a second SELECT statement, which is a subquery.

  5. Like operator

    in the The SQL language is implemented by wildcard characters. the wildcard characters provided by the SQL language are "%", "_", "*" and "[]"; only CHAR,VARCHAR, and You can use the like operator and wildcard characters for data of type TEXT.

    You can use "<>" instead of like when there are no wildcard characters in the query condition . For example:

    SELECT * from teacher T WHERE T.dname does like ' computer '; equivalent to

    SELECT * from teacher T WHERE t.dname <> ' computer ';

    "%" means any number of characters;"_" stands for one character;"[]" matches multiple characters ;

    Use Escape defines the escape character, telling the DBMS that the characters that follow are the actual values, for example:

    Like '%M% ' ESCAPE ' M '; ' The% in front of M is a wildcard character, followed by the actual characters.


Mastering SQL Structured Queries---Learning Note 3

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.