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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:09:23+00:00 2026-06-18T04:09:23+00:00

I have one question. It may be easy for you. I am trying to

  • 0

I have one question. It may be easy for you.

I am trying to build a d3js chord diagram – something like this (http://bl.ocks.org/4062006):

enter image description here

I am however getting the data from my mysql database

My table looks like this:

id gender_taker gender_giver
1     F            M
2     M            M
3     F            M
4     F            F

I want the output to look something like this:

gender_giver gender_taker count(*)
M            F            2
M            M            1
F            F            1

This is easy and can be produced by:

SELECT gender_giver, gender_taker, COUNT(*) FROM data WHEREclauses GROUP BY gender_taker, gender_giver

But I have another issue, I have two another tables that looks like this:
Table 1:

id entryid gender_taker
1   2       F
2   2       M
3   3       F

Table 2:

id entryid gender_giver
1   1       M
2   1       F
3   2       M

entryid is basically id of the first table suggesting that Table2 and Table3 are just subsets of table1

If you combine these three tables it might looks something like:

id gender_taker gender_giver
1     F            M,M,F
2     M,F,M        M,M
3     F,F          M
4     F            F

So as a result for the chord diagram I want all these tables taken into account eventually giving something like:

gender_giver gender_taker count(*)
M            F            6           
M            M            4
F            F            2
F            M            0

Please help me out here.

  • 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-18T04:09:24+00:00Added an answer on June 18, 2026 at 4:09 am
    DROP TABLE IF EXISTS core;
    CREATE TABLE core
    (entry_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
    ,gender_taker CHAR(1) NOT NULL
    ,gender_giver CHAR(1) NOT NULL
    );
    
    INSERT INTO core VALUES
    (1     ,'F','M'),
    (2,'M','M'),
    (3,'F','M'),
    (4,'F','F');
    
    DROP TABLE IF EXISTS table1;
    CREATE TABLE table1
    (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
    ,entryid INT NOT NULL
    ,gender_taker CHAR(1) NOT NULL
    );
    
    INSERT INTO table1 VALUES
    (1   ,2       ,'F'),
    (2   ,2       ,'M'),
    (3   ,3       ,'F');
    
    
    DROP TABLE IF EXISTS table2;
    CREATE TABLE table2
    (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
    ,entryid INT NOT NULL
    ,gender_giver CHAR(1) NOT NULL
    );
    
    INSERT INTO table2 VALUES
    
    (1   ,1       ,'M'),
    (2   ,1       ,'F'),
    (3   ,2       ,'M');
    
    SELECT entry_id
         , GROUP_CONCAT(gender_taker) gender_takers
         , GROUP_CONCAT(gender_giver) gender_givers
      FROM 
         ( SELECT * FROM core
           UNION
           SELECT entryid,gender_taker,NULL FROM table1
           UNION
           SELECT entryid,NULL,gender_giver FROM table2
         ) x
     GROUP 
        BY entry_id;
    +----------+---------------+---------------+
    | entry_id | gender_takers | gender_givers |
    +----------+---------------+---------------+
    |        1 | F             | M,M,F         |
    |        2 | M,F,M         | M,M           |
    |        3 | F,F           | M             |
    |        4 | F             | F             |
    +----------+---------------+---------------+
    
    SELECT a.gender taker
         , b.gender giver
         , COUNT(*)
      FROM 
         (
           SELECT entry_id,'taker' role, gender_taker gender FROM core
           UNION ALL
           SELECT entry_id,'giver', gender_giver FROM core
           UNION ALL
           SELECT entryid,'taker',gender_taker FROM table1
           UNION ALL
           SELECT entryid,'giver',gender_giver FROM table2
         ) a
      JOIN
         (
           SELECT entry_id,'taker' role, gender_taker gender FROM core
           UNION ALL
           SELECT entry_id,'giver', gender_giver FROM core
           UNION ALL
           SELECT entryid,'taker',gender_taker FROM table1
           UNION ALL
           SELECT entryid,'giver',gender_giver FROM table2
         ) b
        ON b.entry_id = a.entry_id
       AND b.role = 'giver'
       AND a.role = 'taker'
     GROUP 
        BY taker
         , giver;
    +-------+-------+----------+
    | taker | giver | COUNT(*) |
    +-------+-------+----------+
    | F     | F     |        2 |
    | F     | M     |        6 |
    | M     | M     |        4 |
    +-------+-------+----------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be an easy question, but if it is one i haven't found
I have one question, I was trying to find more information on the internet
I want to implement this view But I have one question: The text which
This may be more of a best practice question. I have three views (create/details/edit)
OK, this may sound like an odd question so first let me lay out
this may be a easy question, but I really need a light to go
This may be an easy one. I looked through previous questions (and other places
I am new to backbone.js so this may be an easy question. The router
I know this question may have appeared few times here and in the internet.
This may be an easy question but I am a beginner with the linker

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.