Order by with union

0

I have the following tables:

Pessoa1
Id  |    Nome      |  Cidade
1   |   José       |São Paulo
2   |   Maria      |Rio de Janeiro

Pessoa2
Id  |    Nome      |  Cidade
1   |   Pedro      |Belo Horizonte
2   |   Ana        |Vitória

I have the following select:

SELECT * FROM (

    SELECT
          p1.Nome
          ISNULL(CAST(p1.Nome AS VARCHAR),'') + ';' + 
          ISNULL(CAST(p1.Cidade AS VARCHAR),'') AS Resultado
    FROM Pessoa1 p1

    UNION

    SELECT
          p2.Nome
          ISNULL(CAST(p2.Nome AS VARCHAR),'') + ';' + 
          ISNULL(CAST(p2.Cidade AS VARCHAR),'') AS Resultado
    FROM Pessoa1 p2

) AS Resultado
ORDER BY Resultado.Nome

The goal is to bring the column Resultado to the values separated by semicolons, respecting the alphabetical order through the Nome column. Home The issue is that I would like the Nome column not to appear when running select , since it is already included in the Resultado column. Is there any way?

    
asked by anonymous 08.09.2015 / 14:02

1 answer

4

You are using the * selector, which means all fields . Change your SQL from:

SELECT * FROM (

for

SELECT Resultado FROM (

Only this field will be returned.

    
08.09.2015 / 14:15