1
I have two tables in the database:
Tabela1 Id Nome Sexo 1 NomeA Macho 2 NomeC Fêmea
Tabela2 Id Nome Sexo 1 NomeB Macho 2 NomeD Fêmea
I would like to have the following result:
Id Nome Sexo Tabela 1 NomeA Macho Tabela1 2 NomeB Fêmea Tabela2 1 NomeC Macho Tabela1 2 NomeD Fêmea Tabela2
Note that it is in alphabetical order of the two tables.
How could I make a SELECT in the SQL Server to return a result like this?
Using Linq with Entity Framework, is it possible to do the same? (In this case we have db.Table 1 and db.Table 2)
Thank you @Gypsy, but how would I put in alphabetical order taking into account the two tables?
– Jedaias Rodrigues
At the end of query you need to put a order by. Ex.:
... .ToList()).OrderBy(x => x.Nome);
– Jéf Bueno
@Gypsy, it is necessary to use the
ToList()
twice? Wouldn’t it be better to put only once at the end?– Jéf Bueno
@Jéfersonbueno I use to enumerate the result in memory and not depend on the bank when joining the collections. In theory the performance is slightly higher.
– Leonel Sanches da Silva
@Oh gypsy omorrisonmendez, I get it. Thanks for the answer.
– Jéf Bueno
@Jedaiasrodrigues I updated the answer.
– Leonel Sanches da Silva