Results 1 to 5 of 5

Thread: Scalar query

  1. #1
    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.

  2. #2
    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');

  3. #3
    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;

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    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.

Posting Permissions

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