tags:

views:

82

answers:

2

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?

A: 

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.

RageZ
it's already on server side
Michael Buen
@Michael: I mean in C#,PHP,Java whatever he is using for making webpage, if there is any involved.
RageZ
hmm.. ok. "...but why don't you do that on server side?" purported he is doing it on client-side(c#,php,java,etc). i see his last query, it is server-side as it gets.
Michael Buen
+1  A: 

To my knowledge, that's totally fine.

The subqueries won't add any appreciable overhead.

Blorgbeard