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 473045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:08:50+00:00 2026-05-13T00:08:50+00:00

I have the following Chars A C W B J M How can I

  • 0

I have the following

Chars

A
C
W
B
J
M

How can I insert some sequential numbers so that after insertion of the numbers the order of characters will not change?

I mean if I use row_number(), the output Character order is changing like

select 
ROW_NUMBER() over(order by chars) as id,
t.* from @t t

Output:

id chars

1   A
2   B
3   C
4   J
5   M
6   W

My desired expectation is

id chars

1   A
2   C
3   W
4   B
5   J
6   M

Also, I cannot use any identity field like id int identity because I am in the middle of a query and I need to maintain a inner join for achieving something.

I hope I do make myself clear.

Please help.
Thanks in advance

  • 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-05-13T00:08:51+00:00Added an answer on May 13, 2026 at 12:08 am

    There is no implicit ordering of rows in SQL. If some ordering is desired, be it order in which items were inserted or any other order, it must be supported by a user-defined column.

    In other words, the SQL standard doesn’t require the SQL implementations to maintain any order. On the other hand the ORDER BY clause in a SELECT statement can be used to specify the desired order, but such ordering is supported by the values in a particular (again, user defined) column.

    This user defined column may well be an auto-incremented column for which SQL assigns incremental (or otherwise) values to, and this may be what you need.

    Maybe something like…

    CREATE TABLE myTable
    (
       InsertID smallint IDENTITY(1,1),
       OneChar  CHAR(1),
       SomeOtherField VARCHAR(20)
       -- ... etc.
    )
    
    INSERT INTO myTable (OneChar, SomeOtherField) VALUES ('A', 'Alpha')
    INSERT INTO myTable (OneChar, SomeOtherField) VALUES ('W', 'Whiskey')
    INSERT INTO myTable (OneChar, SomeOtherField) VALUES ('B', 'Bravo')
    -- ... etc.
    
    SELECT OneChar
    FROM myTable
    ORDER BY InsertId
    
    'A'
    'W'
    'B'
    --...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some debugging code that looks like the following: #define STRINGIFY(x) #x #define
I have the following in my .vimrc to highlight lines longer than 80 chars:
I have the following line of code for a Windows forms application: return Encoding.ASCII.GetBytes(chars.ToArray());
I have the following string: const char *str = \This is just some random
I have some data similar to the following chart: http://developer.yahoo.com/yui/examples/charts/charts-seriescustomization_clean.html Only difference is that
I'm having the following problem with 2 MySQL tables that have a relation: I
I have the following map structure: std::map<std::pair<int, char>, int> transitions; That represent the transition
Say I have the following: $cars = auto1,auto2,auto3,auto4; If I parse $cars to insert
I have the following string: <stx>1<rs>aaaa<rs>bbbb<rs>cccc<etx> How can i split it in a way
Suppose I have a game that can be played by 2, 3 or 4

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.