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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:22:55+00:00 2026-06-15T15:22:55+00:00

How can I transform this table from this id name 1 sam 2 nick

  • 0

How can I transform this table from this

id name
1  sam
2  nick
3  ali
4  farah
5  josef
6  fadi

to

id1   name1   id2   name2   id3   name3   id4  name4
1     sam     2     nick    3     ali      4   farah
5     josef   6     fadi

the reason i need this is i have a database and i need to do a mail merge using word and I want to print every 4 rows on one page, MS word can only print one row per page, so using an SQL query I want one row to represent 4 rows

thanks in advance

Ali

  • 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-15T15:22:56+00:00Added an answer on June 15, 2026 at 3:22 pm

    You don’t need to create a query for this in Access. Word has a merge field called <<Next Record>> which forces moving to the next record. If you look at how label documents are created using the Mail Merge Wizard, you’ll see that’s how it’s done.

    Updated – Doing this in SQL

    The columns in simple SELECT statements are derived from the columns from the underlying table/query (or from expressions). If you want to define columns based on the data, you need to use a crosstab query.

    First create a query with a running count for each person (say your table is called People), and calculate the row and column position from the running count:

    SELECT People.id, Count(*)-1 AS RunningCount, int(RunningCount/4) AS RowNumber, RunningCount Mod 4 AS ColumnNumber
    FROM People 
    LEFT JOIN People AS People_1 ON People.id >= People_1.id
    GROUP BY People.id;
    

    (You won’t be able to view this in the Query Designer, because the JOIN isn’t comparing with = but with >=.)

    This query returns the following results:

    id  Rank  RowNumber  ColumnNumber
    1   0     0          0
    2   1     0          1
    3   2     0          2
    4   3     0          3
    5   4     1          0
    6   5     1          1
    

    Assuming this query is saved as Positions, the following query will return the results:

    TRANSFORM First(Item) AS FirstOfItem
    SELECT RowNumber
    FROM (
        SELECT ID AS Item, RowNumber, "id" &( ColumnNumber + 1) AS ColumnHeading
        FROM Positions
    
        UNION ALL SELECT Name, RowNumber, "name" & (ColumnNumber +1)
        FROM Positions
        INNER JOIN People ON Positions.id = People.id
    ) AS AllValues
    GROUP BY AllValues.RowNumber
    PIVOT AllValues.ColumnHeading In ("id1","name1","id2","name2","id3","name3","id4","name4");
    

    The UNION is there so each record in the People table will have two columns – one with the id, and one with the name.

    The PIVOT clause forces the columns to the specified order, and not in alphabetical order (e.g. id1, id2 … name1, name2…)

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

Sidebar

Related Questions

I have this table, from which i'd like to select all the td elements
i have a table like this from | to | value ----------------------- 08:10 |
How can I do a Redirect Rule that transforms this URL: http://localhost/app/Company/HomePage.aspx?COMPANYID=2&FORCESHOWCASE=TRUE&THEMEPREVIEW=3 to this
I have a scene and an object placed in some coordinates. I can transform
In SQL server How can I transform 1 row with varchar columns into a
Can I get Visual Studio to transform the built-in aliases into the System types?
Can somebody give a good explanation of FFT image transform How the FFT transformed
Can any of STL algorithms/container operations like std::fill , std::transform be executed in parallel
Can anyone, please, explain to me how to transform a phrase like I want
How can I transfer specific rows from one MySQL DB on one server to

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.