If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > simple question re: select statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-15-12, 20:47
numberscub numberscub is offline
Registered User
 
Join Date: Jan 2012
Posts: 6
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
.
.
.
Reply With Quote
  #2 (permalink)  
Old 01-15-12, 21:13
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
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.
Reply With Quote
  #3 (permalink)  
Old 01-15-12, 23:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,540
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 01-16-12, 00:28
numberscub numberscub is offline
Registered User
 
Join Date: Jan 2012
Posts: 6
r937 -

Thanks very much.
Reply With Quote
  #5 (permalink)  
Old 01-16-12, 11:11
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
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>
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On