Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

T-Sql query

$
0
0

Hi All,

I am looking for a query for a certain scenario mentioned below.

I have a table person and the query below shows the Original Result.

I am looking for a query that would populate result as shown in Expected result.

I have a solution using union all, but looking for a better query so i dont need to run twice query.

My Solution using Union all

Select Id, Name, City from Person

Union all

Select AddressId, Name, City from Person

Query:

Select * from Person

Original Result:

Id   Name   AddressId     City 

1  Joseph   10              Erie

2  Tom       20  Pittsburgh

Expected Result:

Id   Name     City

1    Joseph  Erie

10   Joseph  Erie

2   Tom      Pittsburgh

20  Tom Pittsburgh

Please provide your result or comments.







Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>