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 > General > Database Concepts & Design > Scalar query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-08-06, 20:42
vk101 vk101 is offline
Registered User
 
Join Date: Mar 2006
Posts: 43
Scalar query

I was just reading about scalar queries, and I have some questions:

Can a scalar query return more than one column, albeit in only one record?

Must a scalar query return one record, or can it potentially return 0? (i.e. A join returns nothing.)

Where else, apart from scalar subqueries, is the distinction between a scalar query and 'regular' query (what's the opposite of a scalar query) necessary or useful?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 08-09-06, 01:21
Mucman Mucman is offline
Registered User
 
Join Date: Dec 2002
Location: Vancouver, BC
Posts: 35
I've personally always assumed Scalar queries were ones that returned a SELECT statement with a { MAX, COUNT, MIN, SUM, etc... }. That way a result is always returned.
__________________
INSERT INTO Jokes (statement) VALUES ('Here is my witty SQL signature');
Reply With Quote
  #3 (permalink)  
Old 08-09-06, 08:59
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
I don't know how universal the term is, but in Oracle a scalar [sub]query returns 0 or 1 rows and 1 column, resulting in a null or a scalar value. It is used in the SELECT part of another query like this:

select dept.name, (select count(*) from emp where emp.deptno = dept.deptno) as num_emps
from dept;
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #4 (permalink)  
Old 08-09-06, 09:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
the term is quite universal (how's that for a definitive response, eh)

i've only ever seen it used for scalar subqueries, though, never for scalar queries
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 08-16-06, 21:54
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
I always thought a scalar function could be used in a query and did something to each row like a substring or a math function like cosine. The functions that operated on a group of rows were referred to as column functions like count or average. I don't know if the terminoligy applies similarly when talking about queries.
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