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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:04:41+00:00 2026-05-14T09:04:41+00:00

I have a MySQL InnoDB table laid out like so: id (int), run_id (int),

  • 0

I have a MySQL InnoDB table laid out like so:
id (int), run_id (int), element_name (varchar), value (text), line_order, column_order

`MyDB`.`MyTable` (
  `id` bigint(20) NOT NULL,
  `run_id` int(11) NOT NULL,
  `element_name` varchar(255) NOT NULL,
  `value` text,
  `line_order` int(11) default NULL,
  `column_order` int(11) default NULL

It is used to store data generated by a Java program that used to output this in CSV format, hence the line_order and column_order.
Lets say I have 4 entries (according to the table description):

1,1,'ELEMENT 1','A',0,0
2,1,'ELEMENT 2','B',0,1
3,1,'ELEMENT 1','C',1,0
4,1,'ELEMENT 2','D',1,1

I want to pivot this data in a view for reporting so that it would look like more like the CSV would, where the output would look this:

---------------------
|ELEMENT 1|ELEMENT 2| <--- Element Name
---------------------
|   A     |   B     | <--- Value From line_order = 0
---------------------
|   C     |   D     | <--- Value From line_order = 1
---------------------

The data coming in is extremely dynamic; it can be in any order, can be any of over 900 different elements, and the value could be anything. The Run ID ties them all together, and the line and column order basically let me know where the user wants that data to come back in order. I want it to sort/group by line and column order in the displayed matrix.

  • 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-14T09:04:41+00:00Added an answer on May 14, 2026 at 9:04 am

    You can do that with a self join:

    select e1.element_name, e1.value, e2.value
    from MyTable e1
    inner join MyTable e2
    on e1.element_name = e2.element_name
    and e2.line_order = 1
    where e1.line_order = 0
    

    The from selects line_order = 1, the inner join selects line_order = 2.

    Switch inner join to cross join if you’d like to return elements with only one line_order.

    In reply to your comment, you could write out a fixed number of elements like:

    select
        line_order
    ,   max(case when element_name = 'element 1' then value end) as Element1Value
    ,   max(case when element_name = 'element 2' then value end) as Element2Value
    ,   max(case when element_name = 'element 3' then value end) as Element3Value
    ,   ...
    from MyTable
    group by line_order
    

    The max() construct assumes that (element_name, line_order) is unique.

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

Sidebar

Related Questions

I have the following MySQL (version 5.1) table (InnoDB): Username varchar(50) Sequence int(11) FileType
I have a MySQL-InnoDB table with 350,000+ rows, containing a couple of things like
I have a MySQL InnoDB table with 238 columns. 56 of them are TEXT
I have a MySQL InnoDB table, events , with 3 rows: event_id ---> int
I have MySQL InnoDB table utf-8 encoded. This table has only id and name
I have a MySQL InnoDB table on a RedHat Enterprise Linux 4 server, and
I have a MySQL InnoDB table with a status column. The status can be
I have the following MySQL/InnoDB table. I added a compound index as the primary
I have an InnoDB table in mysql with utf8 charset and utf8_general_ci collation. After
We have a very large (10million+) row table stored in MySql using the InnoDB

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.