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

  • Home
  • SEARCH
  • 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 195087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:39:03+00:00 2026-05-11T16:39:03+00:00

How can I rewrite the query select col1 from tbl1 so it splits the

  • 0

How can I rewrite the query “select col1 from tbl1” so it splits the results into three columns – each column sorting the results vertically?

So if the data I’m getting back is:

aaa
bbb
ccc
ddd
eee
fff
ggg

I need the query to return it as:

aaa  ddd  ggg
bbb  eee
ccc  fff

Is this possible? 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-05-11T16:39:03+00:00Added an answer on May 11, 2026 at 4:39 pm

    In truth, this should not be done in SQL. Unless the pairing of aaa, ddd, and ggg has some meaning then this is client-side formatting and shouldn’t be done on the server.

    EDIT:

    In the interests of an intellectual exercise, something like this seems to work.

    select
        f1.data, f2.data, f3. data
    
    from (select data, ROW_NUMBER() over (order by data) as row_num from your_table) f1
    
    left join (select data, ROW_NUMBER() over (order by data) as row_num from your_table) f2 on f2.row_num = f1.row_num + (select CEILING(COUNT(1) / 3) + 1 from your_table)
    left join (select data, ROW_NUMBER() over (order by data) as row_num from your_table) f3 on f3.row_num = f1.row_num + (select CEILING(COUNT(1) / 3) + 1 from your_table) * 2
    
    where f1.row_num between 1 and FLOOR((select COUNT(1) from your_table) / 3) + 1
    

    But, again, I suspect that this is really something that should be done client-side, NOT in SQL.

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

Sidebar

Related Questions

How can i rewrite the below query to return results with few IO operation
Consider the below SQL query INSERT INTO [dbo].[PartnerCommissionData] SELECT X.* FROM ( SELECT cs.partner_id
Can anyone help me rewrite this query without a distinct clause? select a.rec_type ,
Do you know how to rewrite these this query in MySQL ? I can't
I have a following query (simplified): SELECT Id FROM dbo.Entity WHERE 1 = ALL
How can I rewrite this linq query to Entity on with lambda expression? I
I have code to generate four cars from a DB with their photos: $l=$database->query(SELECT
How I can rewrite following query that I will take minus Correction and Used
I have the following hive query: select count(distinct id) as total from mytable; which
I have the following query I need help with. SELECT a.artist, a.facepic FROM artists_vs

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.