php - SQL COUNT from one table where condition from another table is true -


okay, let's have 2 tables, "tablea" , "tableb". in table have column "c", , in table b have column "d" , column "e".

tablea contains lot of rows can contain same value in column c. tableb contains lot of rows, column d has unique (it's autoincrement number). tableb's column e can contain same value in different rows. well, column c , column d contain same numbers.

example tables

tablea  id     c ---------- 1      1 2      1 3      2  tableb  d    e ---------- 1    1 2    0 3    0 

now, want count rows in tablea in column c, have figured out how do. however, additionally want give me result count of c equivalent value in d has e of "1".

so, have tried this, failing , cannot think of i'm doing wrong or how fix it. googling count gets me results dealing 1 table.

in example, want count c id number matches in tableb column d e = 1 (so, tableb column d = 1), , return count, want return me (or effect):

c count(*) descending 1 2

select tablea.c, count(*) tablea, tableb tableb.e = 1 group tablea.c order count(*) desc 

if makes sense...

you don't join 2 tables on column

select a.c, count(*) tablea join tableb b on (c = d) e group a.c order count(*) desc 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -