sql - Select two counts in one query -



sql - Select two counts in one query -

i have users(user,pass,email) table , want count of user user='someuser' , count of email email='someemail' in 1 query , came that:

select ( select count( user ) users user = 'someuser' ), ( select count( email ) users email = 'someemail' ) users

but i'm wondering if there improve way of doing that? in advance :)

no right way in case. counts 0 or 1 , satisfied nc index.

in case want scan more data, can more efficient this:

select sum(case when user = 'x' 1 end) usercount, sum(case when email = 'x' 1 end) emailcount users

this scan table. depends on info version faster. in case, yours faster.

sql count

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -