SQL Alternative to Virtual Table using “With” Keyword

Let’s say I have a table called States with the following columns and data.

StateTable

Now let’s say I need to create a virtual table that consists of the ID and Abbreviation columns only.  I can do this by using the “with” keyword.  Here’s an example:

with myVirtualTable as (
Select ID, Abbreviation
From States
)

select * From myVirtualTable

Here are the results:

results

need

Advertisements

About Brian McKay
Software Architect

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: