Results 1 to 4 of 4

Thread: SubQuery

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Answers
    2

    SubQuery

    How is subquery used in sqlserver?I mean the command used for subquery?


  2. #2
    Expert Member
    Join Date
    Sep 2006
    Answers
    130

    Re: SubQuery

    Hi Chitra,

    A subquery is a select statement that is embedded in a clause of another select statement.
    A subquery is a SELECT query that returns a single value and is nested inside a SELECT, INSERT, UPDATE, or DELETE statement, or inside another subquery.

    Here is a simple subquery example where the employee details of maximum salary holder is retrieved,
    Code:
    SELECT ename, empno, sal from Northwind.emp_new a
    where sal = (SELECT MAX(sal) FROM Northwind.emp_new b)


    *** Innila ***

  3. #3
    Expert Member
    Join Date
    Jun 2006
    Answers
    410

    Re: SubQuery

    A correction,

    It is not true that A subquery is a SELECT query that returns a single value. Subquery can also return set of values... Here is an example,

    SELECT ename, empno, sal from Northwind.emp_new a
    where sal in (SELECT MAX(sal) FROM Northwind.emp_new b group by dept)


  4. #4
    Expert Member
    Join Date
    Sep 2006
    Answers
    130

    Re: SubQuery

    Yeah true.
    Nice that u have mentioned the correction, James.

    *** Innila ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact