Subqueries examples

  • Someone new to SQL asked me to show him a dozen of subqueries samples for Northwind or AdventureWorks databases. Does anyone know where i could find such samples?
    I can only come up with a couple of basic examples (like 'show all products that have never been ordered...). 
    thanks.

    Likes to play Chess

  • VoldemarG - Sunday, March 17, 2019 8:09 AM

    Someone new to SQL asked me to show him a dozen of subqueries samples for Northwind or AdventureWorks databases. Does anyone know where i could find such samples?
    I can only come up with a couple of basic examples (like 'show all products that have never been ordered...). 
    thanks.

    On a high level, you got two options here, CTE or SubQuery, the latter has two further options of correlation. Anyone asking you of dozen of examples of what they don't know what is sounds a bit peculiar to say the least.
    😎

  • This request also sounds odd to me. I'm also a newbie and I don't even know what to ask online until I encounter something new I can't figure out. Odd that I come to visit the site today and see this question as I just downloaded the Adventure Works DB to look at Pivots.

    -Mark
    MSSQL 2019 Standard, Azure Hosted. Techie/Sysadmin by trade; Three years as a "DBA" now.

  • usererror - Monday, March 18, 2019 7:25 AM

    This request also sounds odd to me. I'm also a newbie and I don't even know what to ask online until I encounter something new I can't figure out. Odd that I come to visit the site today and see this question as I just downloaded the Adventure Works DB to look at Pivots.

    If by "pivots", you mean the PIVOT operator, have a look at the following two articles...
    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns[/url]
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs[/url]

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Jeff Moden - Monday, March 18, 2019 10:09 AM

    usererror - Monday, March 18, 2019 7:25 AM

    This request also sounds odd to me. I'm also a newbie and I don't even know what to ask online until I encounter something new I can't figure out. Odd that I come to visit the site today and see this question as I just downloaded the Adventure Works DB to look at Pivots.

    If by "pivots", you mean the PIVOT operator, have a look at the following two articles...
    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns[/url]
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs[/url]

    Jeff, that is exactly what I meant. 🙂 I have been looking at some other articles about PIVOT.

    -Mark
    MSSQL 2019 Standard, Azure Hosted. Techie/Sysadmin by trade; Three years as a "DBA" now.

Viewing 5 posts - 1 through 4 (of 4 total)

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