Select 1 with SELECT null (GO)

Source: Internet
Author: User

1.Select 1

Here I mainly discuss the following SELECT statements:

Table is a data table, assuming that the table has a row number of 10 rows, the same as the same.

1:select 1 from table

2:select count (1) from table

3:select sum (1) from table

For the first SELECT statement, I just started to think that the "1" represents the column name, from 2, 3 kinds of straight-forward results:) a little shameless. But through my own observation, so I think it is wrong, so I tested in SQL Server, found the result is as follows:

1: The test results, the same number of rows and table table row number of temporary columns (so called, I do not know what to call), the column value of each row is 1;

2: A number is obtained, which is the number of rows of table tables;

3: A number is obtained, which is the number of rows of table tables;

Then I use the "2" test, the results are as follows:

1: A temporary column with the same number of rows as the table row, and a column value of 2 for each row;

2: A number is obtained, which is the number of rows of table tables;

3: Draw a number that is the number of rows in table x2

Then I tested it with a larger number:

1: A temporary column with the same number of rows as table rows, and the column value of each row is the number I write after the select;

2: A number is still obtained, which is the number of rows of table tables;

3: Draw a number that is the number of rows of table tables x is written after the Select

In summary: I found that the first way to write is to increase the temporary column, the column value of each row is written in the number of select, and the second is that regardless of how a value of count (a) changes, the resulting value is always the number of rows in table tables, and the third is to calculate the sum of temporary columns.

2.Select NULL

Select NULL is similar to select 1 except that the returned column value is null, and when used with exists, the exists subquery remains true as long as there are rows returned. and select 1 do not pass, the count and SUm functions cannot be used in select NULL.

Null is a special value that is neither empty nor a space, but an indeterminate value.
The following code
SELECT NULL
From addresses
WHERE address_id = 1
The meaning is that there are several rows in table addresses that satisfy the condition address_id = 1 to return a few rows of null values.

Select 1 with SELECT null (GO)

Related Article

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.