Results 1 to 6 of 6

Thread: [RESOLVED] Sub-select

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Resolved [RESOLVED] Sub-select

    Hi,

    I will need a hint on how to write a mssql query.
    I will like to run two SQL query as one query.

    1) Select * from xxx where yyy=000 from zzzz
    2) select user , sum(aaa+bbb) from xxx where hhh=4

    i would like to run the second query on the result i will get from query 1. I'm not sure which function to use.

    Thx

  2. #2
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Sub-select

    Hello,
    If you're still looking for responses, please post a script that will

    a) Create necessary table structure.
    b) Insert some data into these table structures.
    c) Desired output from this data. How does the output look like?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  3. #3
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Sub-select

    Like this:

    select user , sum(aaa+bbb)
    from (Select * from xxx where yyy=000 from zzzz) AS www
    where hhh=4

  4. #4

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Sub-select

    Hi,

    it's giving me an error on the second from and as

    SELECT user, sum((a,b))
    group by user
    from
    (select * FROM xxxxkmain where net>0 ) as aaa
    thx
    Last edited by met0555; Jan 19th, 2012 at 10:03 AM.

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Sub-select

    The group by should be after the "from", like this:
    Code:
    SELECT user, sum((a,b))
    from (select * FROM xxxxkmain where net>0 ) as aaa 
    group by user

  6. #6

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: Sub-select

    Thx, for the sample, my code is now working as expected

Posting Permissions

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



Click Here to Expand Forum to Full Width