Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2010
    Posts
    10

    Unanswered: Combining Selects with different where's

    Can I combine several queries with different wheres so that the results show 1 line?

    if i have

    select * from history where package='shoes' and maildate = '20090909'

    and

    select * from history where package='jacket' and maildate = '20090808' and offertype >' '

    can i combine those 2 to have the results on 1 line?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    combine those two queries? sure

    results on one line? please give an example
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2010
    Posts
    10
    Quote Originally Posted by r937 View Post
    combine those two queries? sure

    results on one line? please give an example


    Sure,

    I should specify that i do select count(*) for both queries

    usually I would run those 2 queries and the results would be something like

    shoes 55

    jacket 100


    it would be 2 different sections on the results pane

    is there a way to have it as

    shoes jacket
    55 100

    so that everything will be on 1 section

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT ( SELECT COUNT(*) FROM shoes ) AS shoes
         , ( SELECT COUNT(*) FROM jackets ) AS jackets
    notice that this is a far cry from your original request where you were using the dreaded, evil "select star"
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Mar 2010
    Posts
    10
    Quote Originally Posted by r937 View Post
    Code:
    SELECT ( SELECT COUNT(*) FROM shoes ) AS shoes
         , ( SELECT COUNT(*) FROM jackets ) AS jackets
    notice that this is a far cry from your original request where you were using the dreaded, evil "select star"
    I'm one dumb person lol, thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •