1

I have a MySQL query which provides the following result, enter image description here

The query used is

SELECT  modi, aid FROM (SELECT 
 GROUP_CONCAT(id) his,
an_id aid, 
GROUP_CONCAT(m_id) modi
FROM 
ah 
GROUP BY an_id, m_id) t1
GROUP BY aid, modi
order by aid;

Now I need a MySQLquery which will give me a result set where if columnaidhas the same value in two rows should create a new column with sameaidandmodi`.

For example, the first two rows in the image as same aid but different modi. The result I need should have 3 column and the row should look like,

aid           modi                  modi2
27     6,6,6,6,6,6,6,6,6              8

I am very new to SQL. Thanks in advance

1
  • 1
    MySQL is not the same as Oracle.. Besides the how to ask (stackoverflow.com/help/how-to-ask) guidelines requires you provide reproducible data a image isn't reproducible data Commented Oct 30, 2018 at 16:20

1 Answer 1

1

Well, one method is:

SELECT aid, min(modi) as modi1, max(modi) as modi2
FROM (SELECT an_id as aid, 
             GROUP_CONCAT(m_id) as modi
      FROM annotation_history ah
      GROUP BY an_id
    ) t1
GROUP BY aid
HAVING min(modi) <> max(modi);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.