sql server 2008 - How to join two table values in SQL -


i have 2 tables namely states & districts . common column in table stateid.

i want display state name under district names in state

result format should below:

tamilnadu

chennai

coimbatore

karnataka

bangalore

mysore .

.

.

pls tel me how join tables above results using sql query.

this should work:

select sc.name         states s2  left join        (select s.statename name,                 s.stateid              states s         union         select c.cityname name,                c.stateid              city c) sc  on sc.stateid = s2.stateid  

output:

tamilnadu
chennai
coimbatore
karnataka
bangalore
mysore


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -