Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Query Optimization  RSS feed

 
sudha swami
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I didn't try it myself but hope this will work.
 
Shailesh Chandra
Ranch Hand
Posts: 1084
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36622
474
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to put it in one query?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!