Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9105849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:12:01+00:00 2026-06-17T02:12:01+00:00

Hi I have two tables table one have County Info and other one have

  • 0

Hi I have two tables table one have County Info
and other one have the RowData

The Country table looks like

Country_ID  Region_ID   Country_Name              Abbreviation Priority
----------- ----------- ------------------------- ------------ -----------
1           1           United States             USA          1
2           1           US                        USA          1
3           1           Canada                    CA           2
4           2           United Kingdom            UK           1
5           2           Germany                   DE           1
6           2           France                    FR           1
7           2           Italy                     IT           1
8           2           Spain                     ES           1
9           2           The Netherlands           NL           1
10          2           Poland                    PL           2
11          2           Russia                    RU           2

and RowData is like

Tr_ID       Countrys
----------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
729541      Germany,United Kingdom
729553      Italy,Poland,Russia,Spain
729580      Austria,Finland,France,Germany,Ireland,Italy,Poland,Portugal,Romania,Russia,Slovakia,Spain,Sweden,Switzerland,The Netherlands,United Kingdom
729726      Italy,Spain,United Kingdom
729737      Austria,United Kingdom

I want to rearrange county’s in as per the priority given in county table

Priority 1 county should be occurs first reaming country next with comma repeated
Please help me on this

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:12:02+00:00Added an answer on June 17, 2026 at 2:12 am

    SQL Fiddle

    MS SQL Server 2008 Schema Setup:

    create table Country
    (
      Country_ID int,
      Region_ID int,
      Country_Name varchar(25),
      Abbreviation varchar(5),
      Priority int 
    );
    
    insert into Country values
    (1 ,  1,   'United States',   'USA', 1),
    (2 ,  1,   'US',              'USA', 1),
    (3 ,  1,   'Canada',          'CA ', 2),
    (4 ,  2,   'United Kingdom',  'UK ', 1),
    (5 ,  2,   'Germany',         'DE ', 1),
    (6 ,  2,   'France',          'FR ', 1),
    (7 ,  2,   'Italy',           'IT ', 1),
    (8 ,  2,   'Spain',           'ES ', 1),
    (9 ,  2,   'The Netherlands', 'NL ', 1),
    (10,  2,   'Poland',          'PL ', 2),
    (11,  2,   'Russia',          'RU ', 2)
    
    create table RowData
    (
      Tr_ID int,
      Countrys varchar(200)
    )
    
    insert into RowData values
    (729541,  'Germany,United Kingdom'),
    (729553,  'Italy,Poland,Russia,Spain'),
    (729580,  'Austria,Finland,France,Germany,Ireland,Italy,Poland,Portugal,Romania,Russia,Slovakia,Spain,Sweden,Switzerland,The Netherlands,United Kingdom'),
    (729726,  'Italy,Spain,United Kingdom'),
    (729737,  'Austria,United Kingdom')
    

    Query 1:

    select R.Tr_ID,
           (
           select ','+C.Country_Name
           from Country as C
           where ','+R.Countrys+',' like '%,'+C.Country_Name+',%'
           order by C.Priority
           for xml path(''), type
           ).value('substring(text()[1], 2)', 'varchar(200)') as Countrys
    from RowData as R
    

    Results:

    |  TR_ID |                                                                COUNTRYS |
    ------------------------------------------------------------------------------------
    | 729541 |                                                  United Kingdom,Germany |
    | 729553 |                                               Italy,Spain,Poland,Russia |
    | 729580 | United Kingdom,Germany,France,Italy,Spain,The Netherlands,Poland,Russia |
    | 729726 |                                              United Kingdom,Italy,Spain |
    | 729737 |                                                          United Kingdom |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables : one table it matchs and the other is teams.
I have two tables. One table contains words. Other table contains points. table words:
I have two tables. One is the probe and the other transcript. Probe table:
Quick method description: I have two tables, lets name them table ONE and table
I have two tables. One user table and one table in which results are
In SQL Server 2008 I have two tables. One table for users: id_user -
In a MySQL database I have two tables linked in a join. One table
I have two tables, content and images (and a ContentImages table for the one
What I have is two tables inside of a mysql database. One table contains
I have two tables one with ID and NAME table 1 ID | NAME

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.