Forums Register Login

Query Optimization

+Pie Number of slices to send: Send
Hi,
Instead of using 2 queries, i would like to use only one to get the output A and B. is there any way to do it.

select description as A
from Area
where status = 0;

select count(id) as B
from Area
where status =1;

regards
sudha
+Pie Number of slices to send: Send


I didn't try it myself but hope this will work.
+Pie Number of slices to send: Send
 

Originally posted by Saif uddin:




On the first look this query is not going to work because this will also count the ids having status as 0. however the query below is counting only ids which have status 1

also the query will display the description having status = 1 which is not expected from first query.


Top of all I am not sure what is the requirement to make a single query because first query SELECT DESCRIPTION AS A FROM AREA WHERE STATUS = 0; will result in multiple rows and second query SELECT COUNT(ID) AS B FROM AREA WHERE STATUS =1; will result in one row only.

Thanks,
Shailesh
+Pie Number of slices to send: Send
Why do you want to put it in one query?
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 925 times.
Similar Threads
value not passing to the while loop
value not passing to the while loop
Happy Memorial Day!
SQL question (not JDBC)
Updating rows in result set, should select for update be used?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:39:08.