Correlated Subqueries -- HOw are they used?

  • I still struggle the the idea of a correlated subquery. Partially because once i think i've gotten it, i don't ever use it.

    Are correlated subqueries always used with some type of mathematical function?

  • No, it's not related to math functions.

    You have a correlated subquery when you select data from a subquery using a where clause that refers to fields in the outer query.

    Example:

    SELECT Name, Salary = (

    SELECT Salary

    FROM Salaries

    WHERE PersonId = Persons.PersonId

    )

    FROM Persons

    WHERE Age > 30

    Sorry for the stupid example, hope you understand it anyway.

    Here, Salaries is correlated to Persons by the clause "WHERE PersonId = Persons.PersonId".

    Hope this helps

    Gianluca

    -- Gianluca Sartori

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply