SQL Plain Statement

Source: Internet
Author: User

Select DISTINCT t_id from Nrc_news
Distinct does not output the same value
Select Top 5 * from Nrc_news;
Retrieving the first five elements
SELECT * from Nrc_news order by t_id;
Sort by child column t_id
Note: When specifying an ORDER BY clause, it should be guaranteed that it is the last note in the SELECT statement, and if not, an error
SELECT * from Nrc_news order by T_id,n_publishtime;
SELECT * FROM Nrc_news ORDER by 4, 5;
Sort by using two rules
SELECT * from Nrc_news order by t_id DESC;
SELECT * from Nrc_news order by t_id ASC;
Descending and ascending
SELECT * from Nrc_news order by t_id Desc,n_publishtime;
The largest t_id are in front and then sorted by time
SELECT * from Nrc_news where t_id=10;
Filter conditions t_id=10
where operator
= equals
<> Not equal to
! = does not equal
< less than
<= less than or equal to
!< not less than
> Greater than
>= greater than or equal to
!> not greater than
Between between the specified two values
Is NULL for null value

Cases:
SELECT * from Nrc_news where t_id <> 10;

! = and <> are usually interchangeable. However, not all DBMS support these two non-equal operators. For example, Microsoft Access support <> do not support! =
SELECT * from Nrc_news where t_id between 3 and 9;
SELECT * from nrc_news where t_id is null;

SELECT * from Nrc_news where t_id between 3 and 9 and n_id<> 3;
SELECT * from Nrc_news where t_id between 3 and 9 or n_id<> 3;

In the SQL statement
Processing of and is preferable to or.
SELECT * from Nrc_news where n_id>8 or n_id<2 and t_id<10;
SELECT * from Nrc_news where (n_id>8 or n_id<2) and t_id<10;

SELECT * from Nrc_news where t_id in (1,2,3,4);
Equals
SELECT * from Nrc_news where t_id=1 or t_id=2 or t_id=3 or t_id=4;
Not can negate the subsequent judgment
SELECT * from nrc_news where not t_id=1;

Use wildcard characters to determine:
SELECT * from nrc_news where n_content like '% is% ';
SELECT * from nrc_news where n_content like ' small% ';
SELECT * from nrc_news where n_content like '% out ';
Note: Please note that null
Where t_id like '% ' does not match null rows

SELECT * from nrc_news where n_title like ' dream _ ';
SELECT * from nrc_news where n_title like ' [Dream spray]% ';
SELECT * from nrc_news where n_title like ' [^ Dream jet]% ';//except dreams and sprays all the opening

Stitching fields:
Select N_title+ ' (' +n_content+ ') ' from nrc_news;
Note: Trim function
Most DBMS support RTrim () (Remove the space to the right of the string), LTRIM () (Remove the space to the left of the string), TRIM () (Remove the space on both sides of the string) function

Select n_id,n_title,n_content,n_id*t_id as number from Nrc_news order by number;

Plus +,-, *,/can be used

SQL Plain Statement

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.