sql - MySql and PHP - Select Count -


i need values database , count rows.

i wrote code:

select author, alias, (select count(*) registry status='ok' , type='h1') count registry status='ok' , type='h1' 

it work, but, how can simplify code? both were condition thereof.

thank you.

if query returning resultset need, "total" count of rows (independent of author , alias), same exact value "count" repeated on each row, rewrite query this:

select t.author      , t.alias      , s.count   registry t  cross   join ( select count(*) `count`            registry c           c.status='ok'             , c.type='h1'        ) s  t.status='ok'    , t.type='h1' 

i don't know if that's simpler, reading statement, think makes more clear resultset being returned.

(i tend favor avoiding subquery in select list, unless there specific reason add one.)

the resultset query bit odd. absent example data, expected output or specification other original query, we're guessing. query in answer replicates results original query, in way that's more clear.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -