locked
How to show all and selected country data joining from two table RRS feed

  • Question

  • User264732274 posted

    suppose i have one country master table which has two fields called countryid and name and i have another table call user country. which has few fields like

    userid, countryid

    initially i have to show all country id and name when there is no data in user country table.

    when user select few country data like name and id and save then those selected country id and userid should be saved in user country table

    but when we reload data then we have to show all country data and also with selected country data from user country table.

    now tell me how could i issue a sql which give me all country data with also user select country data with some indication by which i can understand which country user has selected because i have mark those country with some color in front end. thanks

    Sunday, May 8, 2016 10:25 AM

All replies

  • User-369506445 posted

    hi

    you can try below script :

    select * from  dbo.country
    join dbo.usercountry on country.countryid=usercountry.countryid

    and if you want fetch countries for each user , try below code :

    select * from  dbo.country
    join dbo.usercountry on country.countryid=usercountry.countryid
    where usercountry.userid=1

    Sunday, May 8, 2016 10:36 AM