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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:44:08+00:00 2026-05-31T06:44:08+00:00

Following this article , I’ve been able to partly transpose a mySQL table. This

  • 0

Following this article, I’ve been able to partly transpose a mySQL table. This is the table:

CREATE TABLE  `test`.`treat` (
`patient` INT NOT NULL ,
`pathology` VARCHAR( 15 ) NOT NULL ,
`present` VARCHAR( 15 ) NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;

then, insert some data:

INSERT INTO `test`.`treat` (`patient`, `pathology`, `present`) 
VALUES ('1', 'myeloid', 'yes'), ('2', 'lymphoid', 'yes'), ('2', 'myeloid', 'no'), ('3', 'myeloid', 'no'), ('4', 'lymphoid', 'yes');

and now I need to get what patients are affected by lymphoid or myeloid pathologies:

SELECT patient,
  GROUP_CONCAT(if(pathology='myeloid', present, NULL)) AS 'myeloid',
  GROUP_CONCAT(if(pathology='lymphoid', present, NULL)) AS 'lymphoid'
FROM treat
GROUP BY patient

I get a table like this that shows when a patient has suffered one of these pathologies or NULL if there is not information available:

patient  myeloid  lymphoid
1        yes      NULL
2        no       yes
3        no       NULL
4        NULL     yes

These data correspond to periodic tests. I’ve ommited the test parameter for simplicity (test INT NOT NULL). But the problem is when I have two data for the same patient. For example, let’s add the test key and a new test for patient 2 (all previous test values corresponds to test 1):

INSERT INTO `test`.`treat` (`patient`, `pathology`, `present`, `test`) 
VALUES ('2', 'myeloid', 'yes', '2');

If we run the query we get this table:

patient  myeloid  lymphoid
1        yes      NULL
2        no,yes   yes
3        no       NULL
4        NULL     yes

Patient number 2 has a myeloid line that is produced by *GROUP_CONCAT* with two comma separated values. I need to have a line for each value, like this:

patient  myeloid  lymphoid
1        yes      NULL
2        no       yes
2        yes      NULL
3        no       NULL
4        NULL     yes

What have to do to take into account test number?

  • 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-31T06:44:10+00:00Added an answer on May 31, 2026 at 6:44 am

    Just add test to your grouping –

    SELECT
        patient,
        GROUP_CONCAT(IF(pathology='myeloid', present, NULL)) AS 'myeloid',
        GROUP_CONCAT(IF(pathology='lymphoid', present, NULL)) AS 'lymphoid'
    FROM treat
    GROUP BY patient, test
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C following this article ( http://blogs.msdn.com/oldnewthing/archive/2006/12/21/1340571.aspx ), we have succesfully been able to
I am following this great article on how to create a Provider framework in
I'm trying to create an RCP application following this article but failing to add
I have been learning RESTful webservices following this tutorial http://www.vogella.de/articles/REST/article.html . As I understand,
I am trying to create a custom datasource control. I have been following this
I'm building a Windows service and following this MSDN article , but I'm stuck
following this link i was able to load and read pixels from a .gif.
I've been following this tutorial (lesson 6) in order to build and deploy a
I'm following this guide: http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_01/programs.html and I'm trying to create my first ruby program.
I following this article for sending SMS it is a winform application.. I have

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.