Query to Join Month and Year

Database
Fan

Query to Join Month and Year

Hi I am pretty new to SQL, can anyone assist me in joining a month and year column together?  The two columns are named "month" & "year" and I am trying to join them together.  


Accepted Solutions
Teradata Employee

Re: Query to Join Month and Year

Considering that you are new to SQL, it occurs to me that I may not know what you mean by "join!"  Perhaps you want to combine "month" and "year" into one string; in that case, Select "month" || "year" from <table-name>.  You can add a separator, such as: Select "month" || '/' || "year" from <table-name>.  || is known as the contatenation operator.

 

Usually the term join refers to combining columns from two or more tables into another table known as the result set.  It is highly unusual to join on date components, as dates are usually attributes, not keys.  An exception might be a reference table that contains events of each month, such as ('January',2017,'Snowmobile racing'), ('February',2017,'Valentine''s Day'), etc.  Then this could be joined to a fact data table via: Select ..., M.Event, ... from Facts F, Months M where F."month" = M."month" and F."year" = M."year".

1 ACCEPTED SOLUTION
2 REPLIES
Teradata Employee

Re: Query to Join Month and Year

Considering that you are new to SQL, it occurs to me that I may not know what you mean by "join!"  Perhaps you want to combine "month" and "year" into one string; in that case, Select "month" || "year" from <table-name>.  You can add a separator, such as: Select "month" || '/' || "year" from <table-name>.  || is known as the contatenation operator.

 

Usually the term join refers to combining columns from two or more tables into another table known as the result set.  It is highly unusual to join on date components, as dates are usually attributes, not keys.  An exception might be a reference table that contains events of each month, such as ('January',2017,'Snowmobile racing'), ('February',2017,'Valentine''s Day'), etc.  Then this could be joined to a fact data table via: Select ..., M.Event, ... from Facts F, Months M where F."month" = M."month" and F."year" = M."year".

Highlighted
Fan

Re: Query to Join Month and Year

Thank you GJColeman that worked.  Yes, it was very weird but this particular table had the month and year in seperate columns.  

 

Month    Year
January  2017