mysql - SELECT OTHER TABLE -


i have little bit issue mysql query

so have table named "diagnose" , "diagnose master" in "diagnose" there related field & record

idd   |   idmed   |   idf1   |   idf2   |   idf3

1     |      20       |    5     |     8     |     9

2     |      21       |    3     |     -      |    11

3     |      22       |    7     |     1     |     -

4     |      23       |    1     |      -     |     -

5     |      24       |    6     |      2    |     8

...

in "diagnose master"

iddm  |  code  |  name

1        |   a.1    |   abc

2        |   a.2    |   abcd

3        |   b.3    |  abcde

4        |   b.4    |  abcdef

5        |   c.5    | abcdefg

...

i need select diagnose table idf1, idf2, idf3 field replace field name diagnose master output be

idd | idmed |        idf1      |         idf2       | idf3

1    |    20    | abcdefg | abcdefgh | abcdefghij

2    |    21    |   abcde    |          -           | abc

...

how query that?

thank you

you need join diagnosemaster 3 times same table on 3 different columns, using 3 different aliases. try this:

select d.idd, d.idmed, dm1.name idf1, dm2.name idf2, dm3.name idf3      diagnose d     join diagnosemaster dm1 on dm1.idd = d.idf1     join diagnosemaster dm2 on dm2.idd = d.idf2     join diagnosemaster dm3 on dm3.idd = d.idf3 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -