SQL is a beautiful language that’s highly useful for extracting large amounts of data from large data warehouses.

There are a few cool shorthand you can use to make you’re experience go faster.

Abbreviating Table Shorthand

/* here's how you would normally write a shortcut for 
a table name */

select *
from table as t

/* but here's how you can write it without the word as */

select *
from table t

/* seems a bit silly but if you're writing a lot of code
every abbreviation helps, plus it doesn't hamper readability,
 in my opinion */

Abbreviating Group By and Order By Columns

/* here's how you would normally write out a group by
statement */

select column_1, column_2, count(agg_col)
from table t
group by t.column_1, t.column_2

/* here's how you can speed up the process */

select column_1, column_2, count(agg_col)
from table t
group by 1, 2

/* it's not as readable, but I feel like it's
not too confusing */

Getting Rid of Multiple Or Statements

/* here's how you would normally write out multiple 
or statements */

select column_1, column_2
from table t
where column_1 = 'x' or column_1 = 'y'

/* instead you can just do this */

select column_1, column_2
from table t
where column_1 in ('x', 'y')

/* ok, so this one is more commonly known
but if you don't know this trick you can waste a lot of time
in my opinion */

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s