943,852 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 716
  • MySQL RSS
Jun 8th, 2009
0

2 slelect statement in 1 query..HOW?

Expand Post »
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:

sql Syntax (Toggle Plain Text)
  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:

sql Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jegham is offline Offline
1 posts
since Jun 2009
Jun 8th, 2009
0

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

It is unclear what you exactly want to achieve. Bot hof your queries are identical.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Jun 8th, 2009
0

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

Mean something like this?

MySQL Syntax (Toggle Plain Text)
  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
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 730
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006
Jun 11th, 2009
0

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

hi
If you want all same fields for different id than you can use 'in ' with where clause.
MySQL Syntax (Toggle Plain Text)
  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
Reputation Points: 13
Solved Threads: 15
Junior Poster in Training
Tulsa is offline Offline
77 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Compare 2 time values to get an approximate result
Next Thread in MySQL Forum Timeline: Mysgl error please help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC