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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:43:20+00:00 2026-05-27T04:43:20+00:00

How can I insert to a table a value from grouping other table? That

  • 0

How can I insert to a table a value from “grouping” other table?
That means I have 2 table with different structure.

The table ORDRE with existed DATA

Table ORDRE:

ORDRE ID  |  CODE_DEST | 
-------------------------
    1     |     a      |    
    2     |     b      |    
    3     |     c      |    
    4     |     a      |    
    5     |     a      |    
    6     |     b      |    
    7     |     g      |    

I want to INSERT the value FROM Table ORDRE INTO TABLE VOIT:

 ID_VOIT  |  ORDRE ID  |    CODE_DEST | 
 ---------------------------------------
    1     |     1      |         a    |   
    1     |     4      |         a    |    
    1     |     5      |         a    |   
    2     |     2      |         b    |     
    2     |     6      |         b    |    
    3     |     3      |         c    |     
    4     |     7      |         g    |    
  • 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-27T04:43:21+00:00Added an answer on May 27, 2026 at 4:43 am

    This is my best guess on what you need using only the info available.

    declare @Ordre table
    (
      ordre_id int,
      code_dest char(1)
    )
    declare @Voit table
    (
      id_voit int,
      ordre_id int,
      code_dest char(1)
    )
    
    insert into @Ordre values
    (1,'a'),
    (2,'b'),
    (3,'c'),
    (4,'a'),
    (5,'a'),
    (6,'b'),
    (7,'g')
    
    
    insert into @Voit
    select id_voit, ordre_id, rsOrdre.code_dest
    from @Ordre rsOrdre
    inner join
    (
      select code_dest, ROW_NUMBER() over (order by code_dest) as id_voit
      from @Ordre
      group by code_dest
    ) rsVoit on rsVoit.code_dest = rsOrdre.code_dest
    order by id_voit, ordre_id
    
    
    select * from @Voit
    

    Working Example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How i can insert data into more than one table of an Access database
I have the following Execution statement which creates a table (using data from another
I have the following Query: create table #Result (Reward varchar(40), Value MONEY); insert #Result
I have a table stored on a SQL Server 2008, that associate a value
I have a database and i can insert into it and read from it
Merge can performs insert, update, or delete operations on a target table based on
I can't figure out what's causing my INSERT INTO's to fail to certain table
I know that you can insert multiple rows at once, is there a way
I know that I can insert multiple rows using a single statement, if I
Is there a way that I can insert values into a VB.NET Dictionary when

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.