Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this TSQL V() method/syntax/function?

I have just come across this syntax for defining an inline view...

SELECT myAlias, myAlias1 FROM ( SELECT myCol, myCol1 FROM myTable ) V( myAlias, myAlias1)

I can see what the V is doing, but what is this called and where is it documented? And why would I ever want to do this when I can just define the aliases inside the inline view?

Googling seems not to be working because V is not a word!

like image 910
bbsimonbb Avatar asked Jun 22 '26 14:06

bbsimonbb


1 Answers

V is just another alias - it's the alias for the whole subquery, not for an individual column.

See the derived table line from the syntax for FROM:

   | derived_table [ [ AS ] table_alias ] [ ( column_alias [ ,...n ] ) ]   

V is the table_alias.

when I can just define the aliases inside the inline view

Yes, you often can. But sometimes you're building a complex query with lots of nesting in the individual column expressions, and it's easier to place all of the names (the table_alias and column_aliases) that will be exposed to the remaining parts of the query in one place.

like image 184
Damien_The_Unbeliever Avatar answered Jun 27 '26 00:06

Damien_The_Unbeliever