Results 1 to 7 of 7

Thread: query problem

  1. #1
    Join Date
    Nov 2004
    Posts
    9

    Unanswered: query problem

    Could someone help me with this

    I want to combine the following 2 queries into 1 query where it would give me 2 results (proflad and proftot) but don't know how

    select sum(return-inv)as proflad
    from allbets where com="lad"


    select sum(return-inv)as proftot
    from allbets where com="tot"


    thanks

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    This should work:
    Code:
    SELECT
    (select sum(return-inv) from allbets where com="lad") as proflad
    , (select sum(return-inv) from allbets where com="tot") as proftot

  3. #3
    Join Date
    Nov 2004
    Posts
    9
    I tried that but I still get an error message

    Error: You have an error in your SQL syntax..............

    Any other ideas?

    Thanks

  4. #4
    Join Date
    Oct 2005
    Posts
    5

    version of mysql

    I believe that sub selects are supported from 4.1 and higher, so check your version.

  5. #5
    Join Date
    Nov 2004
    Posts
    9
    I have version 4.0.16

    Is there any way I can run this query with this?

  6. #6
    Join Date
    Oct 2005
    Posts
    5

    pretty sure, you can't

    can you not updrade?

  7. #7
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    The only other thing I can think of would be something like:

    Code:
    select
    sum(return_inv) as return_inv, com 
    from allbets 
    where com="lad" OR com="tot"
    group by com
    but the results will be returned as two separate rows (rather than one row in two columns).

Posting Permissions

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