I have a table that has three columns: myColumn, myColumn2 and myColumn3. The three columns can have a different value but they are all the same type.
I need to do a join such that I merge all the items in the three columns and then group by
If I had a single column, it would be done like this:
select distinct (myColumn), COUNT(myColumn) as 'TotalF'
from FormularioCorto
where idEvento = @idEvento and myColumn <> ''
group by myColumn
The question is:
How do I do a TSQL statement that will allow for me to join the three columns and then group by?
Edit: here is the sample data
I have a table that has 3 columns with the same type
columna columnb columnc
a a b
b a b
c c d
I need to run a tsql that will merge the 3 columns and group by, to get a result like
newcolumn count
a 3
b 3
c 2
d 1
Any ideas?
Thanks in advance
I think you mean concatenate rather than JOIN. JOIN has a very specific meaning with SQL. Use the + operator to concatenate string fields.