SQL Example 8--Select

Source: Internet
Author: User
Tags generator

<title>SQL Example 8–select</title> SQL Example 8–select
    • SQL Create
    • SQL Delete
TruncateTableUser1; # Clear DatabaseSelect* fromUser1;Insert  intoUser1 (ID, username)Values(0,' Test0 ');Insert  intoUser1 (ID, username)Values(1,' test1 ');Insert  intoUser1 (ID, username)Values(2,' Test2 ');Insert  intoUser1 (ID, username)Values(3,' Test3 ');Insert  intoUser1 (ID, username)Values(4,' test4 ');Insert  intoUser1 (ID, username)Values(5,' Test5 ');Insert  intoUser1 (ID, username)Values(6,' Test6 ');Insert  intoUser1 (ID, username)Values(7,' Test7 ');Insert  intoUser1 (ID, username)Values(8,' Test8 ');Insert  intoUser1 (ID, username)Values(9,' Test9 ');Insert  intoUser1 (ID, username)Values(100,' test100 ');Insert  intoUser1 (ID, username)Values(111,' test111 ');Select* fromUser1;
SelectID, username fromUser1where(ID < 5)OR(ID > 90);SelectID, username fromUser1whereIdbetween5 and90; # [5, 90]SelectID, username fromUser1whereId not between5 and90; # ! [5, 90]SelectID, username fromUser1whereId not inch(1, 2, 3, 4, 5);
Select  from where  is  not null; Select  from where  is null;
    • Like wildcard characters
      _: Single character%: 0 or more
      SELECT * from user1;| ID  | username |+-----+----------+|   0 | Test0    | |   1 | Test1    | |   2 | Test2    | |   3 | Test3    | |   4 | Test4    | |   5 | Test5    | |   6 | Test6    | |   7 | Test7    | |   8 | Test8    | |   9 | Test9 | | | |    test100  | | 111 | test111  |
Select  from where  like ' 1__ ';
| ID  | username |+-----+----------+| | test100  | | 111 | test111  |
Select  from where  like ' test___ ';
| ID  | username |+-----+----------+| | test100  | | 111 | test111  |
Select  from where  like ' test1% ';
| ID  | username |+-----+----------+|   1 | test1 | | | |    test100  | | 111 | test111  |
  • Order
    Select  from Order  by username; Select  from Order  by ASC ASC; Select  from Order  by desc;

    The default is ASC (ascending), descending (DESC)

  • Limiit
    • Implementation of PHP paging
    Limit 3         (3 digits only) limit, ten    (return to rank 11 to) limit 1, 1      (for second digit)
  • Alias
    Select ID as userId, username as username from User;select ID, username from user;                        # Two fields Select ID username from user;                         # A field, username is the alias of the ID select ID as username from user;                      # a field, alias
  • Distinct
    TruncateTableUser1;Insert  intoUser1 (ID, username)Values(1,' Test ');Insert  intoUser1 (ID, username)Values(1,' Test ');Insert  intoUser1 (ID, username)Values(1,' Test ');Insert  intoUser1 (ID, username)Values(1,' Test ');Select distinct* fromUser1;

SQL Example 8--Select

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.