Ramesh
Ramesh

Reputation: 145

Is it Proper a way to select count(*) from two different tables

i want count(*) from two different tables and a value from third table

like this:

table A: select count(*) from TABLE_A where grp_id = 1

table B: select count(*) from TABLE_B where grp_id = 1

table C: select totalcount from TABLE_C where grp_id = 1 and AND UserID = 1

so , i framed this query:

select ifnull((select count(*) from TABLE_A where grp_id = 1),0) + ifnull((select count(*) from TABLE_B where grp_id = 1),0)

will it be efficient way to do?

Upvotes: 0

Views: 264

Answers (2)

Blorgbeard
Blorgbeard

Reputation: 103467

To my knowledge, that's totally fine.

The subqueries won't add any appreciable overhead.

Upvotes: 1

RageZ
RageZ

Reputation: 27313

Ramesh,

I think that would be efficient but why don't you do that on server side ? I think it would be more flexible then writing this SQL query.

Upvotes: 0

Related Questions