Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2012
    Posts
    6

    Unanswered: simple question re: select statement

    I have experience with simple queries using MySQL but I am trying to understand a piece of code written for Oracle. In lines 2 and 3, are we basically creating two new fields and populating them with the text "Total"

    Thanks!

    SELECT a.var AS "Var"
    , 'TOTAL' AS "Text"
    , 'TOTAL' AS "Text2"
    , a.var2
    FROM database a
    UNION ALL
    .
    .
    .

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
    SQL> select sysdate , 'TOTAL' AS "Text" , 'TOTAL' AS "Text2"   from dual;
    
    SYSDATE 	    Text  Text2
    ------------------- ----- -----
    2012-01-15 18:12:18 TOTAL TOTAL
    I am not sure what your question is.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by numberscub View Post
    In lines 2 and 3, are we basically creating two new fields and populating them with the text "Total"
    yes, that's right
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jan 2012
    Posts
    6
    r937 -

    Thanks very much.

  5. #5
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    However, UNION (ALL) leads to another option: the first SELECT statement (i.e. the one you posted) might be a header. For example:
    Code:
    SQL> set head off
    SQL>
    SQL> select 'Max salary' as total, 'Max comm' as total
      2  from dual
      3  union all
      4  select to_char(max(sal), '999G990D00'), to_char(max(comm), '999G990D00')
      5  from emp
      6  /
    
    Max salary  Max comm
       5,000.00    1,400.00
    
    SQL>

Posting Permissions

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