954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

2 slelect statement in 1 query..HOW?

Hi all,

I am fairly new when it comes to SQL... and i would like some help

I would like to run 2 select statements in the same time...in order to get my results in a table with 2 columns and 2 rows that shows me the result of my queries

1st query:

select  count(serviceid)
from serviceslog
where serviceid='3'
and partition not like '%test%'
and component not like '%test%'
and component not like '%do not bill%'
and occurence between '2009-05-01 05:00:00' and '2009-06-01 04:59:59'
group by serviceid;


2nd query:

select  count(serviceid)
from serviceslog
where serviceid='3'
and partition not like '%test%'
and component not like '%test%'
and component not like '%do not bill%'
and occurence between '2009-05-01 05:00:00' and '2009-06-01 04:59:59'
group by serviceid;

Any help would be appreciated.

jegham
Newbie Poster
1 post since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

It is unclear what you exactly want to achieve. Bot hof your queries are identical.

verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 

Mean something like this?

select  '1' as rownum, count(serviceid) as id
from serviceslog
where serviceid='1'
and partition not like '%test%'
and component not like '%test%'
and component not like '%do not bill%'
and occurence between '2009-05-01 05:00:00' and '2009-06-01 04:59:59'
group by serviceid

union
 
select '2' as rownum, count(serviceid) as id
from serviceslog
where serviceid='3'
and partition not like '%test%'
and component not like '%test%'
and component not like '%do not bill%'
and occurence between '2009-05-01 05:00:00' and '2009-06-01 04:59:59'
group by serviceid
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

hi
If you want all same fields for different id than you can use 'in ' with where clause.

select  count(serviceid) as id
from serviceslog
where serviceid in ('1','2')
and partition not like '%test%'
and component not like '%test%'
and component not like '%do not bill%'
and occurence between '2009-05-01 05:00:00' and '2009-06-01 04:59:59'
group by serviceid


Thanks

Tulsa
Junior Poster in Training
77 posts since May 2009
Reputation Points: 13
Solved Threads: 15
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You