2 slelect statement in 1 query..HOW?

Reply

Join Date: Jun 2009
Posts: 1
Reputation: jegham is an unknown quantity at this point 
Solved Threads: 0
jegham jegham is offline Offline
Newbie Poster

2 slelect statement in 1 query..HOW?

 
0
  #1
Jun 8th, 2009
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:

  1. SELECT count(serviceid)
  2. FROM serviceslog
  3. WHERE serviceid='3'
  4. AND partition NOT LIKE '%test%'
  5. AND component NOT LIKE '%test%'
  6. AND component NOT LIKE '%do not bill%'
  7. AND occurence BETWEEN '2009-05-01 05:00:00' AND '2009-06-01 04:59:59'
  8. GROUP BY serviceid;

2nd query:

  1. SELECT count(serviceid)
  2. FROM serviceslog
  3. WHERE serviceid='3'
  4. AND partition NOT LIKE '%test%'
  5. AND component NOT LIKE '%test%'
  6. AND component NOT LIKE '%do not bill%'
  7. AND occurence BETWEEN '2009-05-01 05:00:00' AND '2009-06-01 04:59:59'
  8. GROUP BY serviceid;


Any help would be appreciated.
Last edited by peter_budo; Jun 8th, 2009 at 10:40 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: 2 slelect statement in 1 query..HOW?

 
0
  #2
Jun 8th, 2009
It is unclear what you exactly want to achieve. Bot hof your queries are identical.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 827
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 135
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: 2 slelect statement in 1 query..HOW?

 
0
  #3
Jun 8th, 2009
Mean something like this?

  1. SELECT '1' as rownum, count(serviceid) as id
  2. FROM serviceslog
  3. WHERE serviceid='1'
  4. AND partition NOT LIKE '%test%'
  5. AND component NOT LIKE '%test%'
  6. AND component NOT LIKE '%do not bill%'
  7. AND occurence BETWEEN '2009-05-01 05:00:00' AND '2009-06-01 04:59:59'
  8. GROUP BY serviceid
  9.  
  10. UNION
  11.  
  12. SELECT '2' as rownum, count(serviceid) as id
  13. FROM serviceslog
  14. WHERE serviceid='3'
  15. AND partition NOT LIKE '%test%'
  16. AND component NOT LIKE '%test%'
  17. AND component NOT LIKE '%do not bill%'
  18. AND occurence BETWEEN '2009-05-01 05:00:00' AND '2009-06-01 04:59:59'
  19. GROUP BY serviceid
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 77
Reputation: Tulsa is an unknown quantity at this point 
Solved Threads: 15
Tulsa's Avatar
Tulsa Tulsa is offline Offline
Junior Poster in Training

Re: 2 slelect statement in 1 query..HOW?

 
0
  #4
Jun 11th, 2009
hi
If you want all same fields for different id than you can use 'in ' with where clause.
  1. SELECT count(serviceid) as id
  2. FROM serviceslog
  3. WHERE serviceid IN ('1','2')
  4. AND partition NOT LIKE '%test%'
  5. AND component NOT LIKE '%test%'
  6. AND component NOT LIKE '%do not bill%'
  7. AND occurence BETWEEN '2009-05-01 05:00:00' AND '2009-06-01 04:59:59'
  8. GROUP BY serviceid

Thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC