SQL Statement t1, t2 etc

user1847961 picture user1847961 · Dec 4, 2012 · Viewed 14.8k times · Source

Im quite new to SQL and I'm just trying to find out what it means when you use t1, t2 or t3 etc... I cant get my head around it and would just like to learn about it. I've tried looking all over google but i've found nothing yet... Can you help?

Thanks Mw

Answer

Eli Gassert picture Eli Gassert · Dec 4, 2012

t1/t2/t3 are common table aliases for "temp" tables (e.g. subqueries that are made of multiple tables and don't alias nicely).... call it a bit of laziness if that helps :)

SELECT * FROM MyTable t1 means from now on, I'm calling MyTable t1. Another way of writing it would be: SELECT t1.* FROM MyTable t1 or if you didn't use the alias, SELECT MyTable.* FROM MyTable