sql - Count non empty fields in MYSQL -


i have simple mysql table1:

id  1  2  3 

and table2:

 id | question | answer   1 |  how     |    2 |      | fine   3 |      | ok 

and simple query:

select table1.id,count(answer not null) table1 left join table2        on table1.id = table2.id 

i want count non empty answer fields. tried not null it's not working answer column not null , not applicable lead main query return nothing

you try this, capture blank:

select count(id) table answer not null or answer <>'' 

that should grab , count row has value in "answer".

or, if there join:

select     table1.count(id), table2.question         table1 left outer join                       tabel1 on table1.id = table2.id group table1.id,table2.question having      (table2.answer <> '') or (table2.answer not null) 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -