![]() But that person is probably also just showing off or being a pain in the butt. And sure, that person may be technically right. Yes, you might hear some know it all tell you your query would have been more efficient if you did it this way, or that way. You should go with whatever you feel most comfortable with. The most important thing I can tell you on this is that when faced with a multi-step problem that requires one of these methods, there is no wrong choice. ![]() When should we use each of these three methods? When you want to leverage temporary tables, you’ll use a CREATE TEMPORARY TABLE statement, like this… Temporary tables are almost exactly like regular tables, except that they only persist during your current session. Similar to subqueries and CTEs, temporary tables are used to define an entity made up of columns and rows, which you can write additional SELECT statements on. Just like with a subquery, you will write a complete SELECT statement to define columns and rows, but this time you will open it up using a WITH( ), and then later in the same query, you can SELECT data from your CTE, just like you would from a regular table. When you create a CTE, it’s pretty similar to what you do with a subquery, with some slight differences. In practice, you might hear Analysts talking about the subquery as the “inner query”. When you use a subquery, you’re writing one complete SELECT statement, which outputs some number of columns and rows, and then you write another SELECT statement, which SELECTs data from the output of your initial SELECT statement, just like you would with a regular table. With our SQL audience growing, and having varying levels of previous exposure to these concepts, I should start off with some basic definitions and examples (skip over this if you have this down already).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |