MySql link table in union query -


i need select specific sum union query 3 table should be
available in column field, see error error code: 1054. unknown column 'm.id' in 'where clause' m.id in union sub query not visible. how can make work, without functions, via query.

select     m.col1,     m.col2,     p.id,     (         select              sum(cp)          (                 select                       count(*) cp                                        t1 o                                       o.st = 4                       , o.lid = m.id                  union                  select                       count(*) cp                                        t2 oh                                       oh.st = 0                       , oh.lid = m.id                  union                  select                      count(*) cp                                       t3 os                                     os.st = 4                      , os.lid = m.id              ) pp          ) isfb               tm m         join tme mx on m.id = mx.mid         join tp p on m.cid = p.pid 

its hard answer without providing little more information on want

but, start joins in sub queries , like:

            select                   tm.col1, tm.col2, tm.id, count(*) cp                                t1             join                   tm             on                     t1.lid = tm.id             group                   tm.col1, tm.col2, tm.id 

then able join in outer query, like

select     uu.col1,     uu.col2,     tp.id,     sum(uu.cp) (   ** union query goes here ) uu join tp on uu.id = tp.pid group    uu.col1, uu.col2, tp.id 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -