SELECT From UNION possible?

  •  My UNION (shown below) works. It gives me the right results.

    (SELECT Table1.Invoice_No, Table1.Product_Name, Table1.Qty*-1 AS Qty

    FROM Table1

    WHERE Table1.Movement='Out')

    UNION

    (SELECT Table1.Invoice_No, Table1.Product_Name, Table1.Qty

    FROM Table1

    WHERE Table1.Movement='In')

    However, it's when I want to Select something from the query above that's when I get the error message. I was wondering if it was allowed. Thanks again. 

     I am getting a "Incorrect syntax near the keyword 'UNION'." error message from the folowing.

    SELECT *

    FROM

    (SELECT Table1.Invoice_No, Table1.Product_Name, Table1.Qty*-1 AS Qty

    FROM Table1

    WHERE Table1.Movement='Out')

    UNION

    (SELECT Table1.Invoice_No, Table1.Product_Name, Table1.Qty

    FROM Table1

    WHERE Table1.Movement='In')

  • SELECT DT.* FROM

    (

    Your union query

    ) AS DT

    Giving an alias to the union query will work

  •   Ha, ha!  It works!

    Thanks!

  • Also I would just try enclosing your statement inside the parens that David provided.  I think that is the trick and not the alias...



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • AJ - this works only when used as a derived table - unless I'm missing something very obvious in the syntax (if so, could you pl. be kind enough to post an example ?!?!)







    **ASCII stupid question, get a stupid ANSI !!!**

  • You're not missing anything... Maybe I'll send some coffee to aj .

  • Ok - thx. for confirming remi!

    David - You may want to consider changing how your name appears in the posts since we have another (really old time) member of SSC who's also a "David Poole" and funnily enough - stays not too far from where you are - Cheshire, I believe!!!

    You may just end up with an identity crisis!!!







    **ASCII stupid question, get a stupid ANSI !!!**

  • We are one and the same, I've just changed my job.

    Really old time member!!!!!!!! OK I have colleagues who are younger than my album collection but I'm not THAT old!

  • That's funny!

    When I said "old member" I meant member of long standing not chronological years...

    can't figure out why you've "reappeared" as yourself instead of just editing your profile ?!?!?!







    **ASCII stupid question, get a stupid ANSI !!!**

  • Sad though it may be I wanted SSC e-mails to go to my home e-mail address as well as my work address, hence two registrations.

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply