mysql - find the number of occurrences from two columns -


question example :

source | target apple  |   dog dog    |   cat door   |   cat dog    |   apple cat    |   dog 

result :

apple dog 2 dog   cat 2 door  cat 1 

here question, example:

i trying count apple , dog occurrence source , target. count 2, is; apple dog , dog cat.

in same way; dog cat , cat dog, occur 2 times.

how can mysql ?

the data large, simple example.

assuming source , target joined id as:

select     firstvalue,     secondvalue,     count(*) mycount (select     sourcetable.value firstvalue,     targettable.value secondvalue     sourcetable      inner join targettable on sourcetable.idvalue = targettable.idvalue union select     targettable.value firstvalue,     sourcetable.value secondvalue     targettable      inner join sourcetable on targettable.idvalue = sourcetable.idvalue)  group     firstvalue,     secondvalue 

reading question again i'm unsure if these 2 columns in same table. if query can simplified to:

select     firstvalue,     secondvalue,     count(*) mycount (select     sourcecolumn firstvalue,     targetcolumn secondvalue     mytable union select     targetcolumn firstvalue,     sourcecolumn secondvalue     mytable)  group     firstvalue,     secondvalue 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -