Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: What does NULL as ColumnName imply

I understand that AS is used to create an alias. Therefore, it makes sense to have one long name aliased as a shorter one. However, I am seeing a SQL query NULL as ColumnName What does this imply?

SELECT *, NULL as aColumn
like image 377
Shamim Hafiz - MSFT Avatar asked Jun 28 '13 17:06

Shamim Hafiz - MSFT


People also ask

What does NULL as do in SQL?

SQL uses NULLs as a special flag that signals the lack of a value for a field or a variable. NULLs should be used wisely so the database gives a faithful picture of the reality it represents.

What NULL represents in SQL?

In SQL, null or NULL is a special marker used to indicate that a data value does not exist in the database. Introduced by the creator of the relational database model, E. F.

IS NULL value same as zero in SQL give reason?

No its not the same as null means a value that is unavailable unassigned or unknown and zero is a defined value. The intersection of any two disjoint sets is a null set. Justify your answer.

Does count (*) include NULL?

The notation COUNT(*) includes NULL values in the total. The notation COUNT( column_name ) only considers rows where the column contains a non- NULL value.


2 Answers

Aliasing can be used in a number of ways, not just to shorten a long column name.

In this case, your example means you're returning a column that always contains NULL, and it's alias/column name is aColumn.

Aliasing can also be used when you're using computed values, such as Column1 + Column2 AS Column3.

like image 124
LittleBobbyTables - Au Revoir Avatar answered Oct 20 '22 23:10

LittleBobbyTables - Au Revoir


When unioning or joining datasets using a 'Null AS [ColumnA] is a quick way to make sure create a complete dataset that can then be updated later and a new column does not need to be created in any of the source tables.

like image 40
Jessie Avatar answered Oct 20 '22 23:10

Jessie