Skip to main content

SQL Journey: Blog #14



I am now on what Alex the Analyst would call the advanced SQL queries. First off, the Common Table Expression or CTEs. Based on what I understood in the video, CTEs is similar to a function or class in Python which you can call out. It is just how I felt when I first encountered this expression.

Now, in this particular case, I tried to replicate what Alex is doing but also not copying the codes that he is using. I am just simply trying to understand what the expression that was used (which starts with WITH) and then observe how he used the said expression.

This was my code.


Now this code, resulted in the following error.

Msg 8156, Level 16, State 1, Line 84
The column 'EmployeeID' was specified multiple times for 'CTE_Employee'.

What does someone do in this day and age if we encounter something that bogs us down? We go to the internet especially to AI tools to aid us out. And, apparently, these tools will really come in handy. It stated that the error occurred because I am joining two tables which has the same "EmployeeID" column. Therefore, I must specify the columns which I need in the query. As a result,


Query Results:


Comments