Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3220722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:47:38+00:00 2026-05-17T15:47:38+00:00

I recently learned about Recursive Common Table Expressions (CTEs) while looking for a way

  • 0

I recently learned about Recursive Common Table Expressions (CTEs) while looking for a way to build a certain view of some data. After taking a while to write out how the first iteration of my query would work, I turned it into a CTE to watch the whole thing play out. I was surprised to see that grouping didn’t work, so I just replaced it with a “Select TOP 1, ORDER BY” equivalent. I was again surprised that “TOP” wasn’t allowed, and came to find that all of these clauses aren’t allowed in the recursive part of a CTE:

  • DISTINCT
  • GROUP BY
  • HAVING
  • TOP
  • LEFT
  • RIGHT
  • OUTER JOIN

So I suppose I have 2 questions:

  1. In order to better understand my situation and SQL, why aren’t these clauses allowed?
  2. If I need to do some sort of recursion using some of these clauses, is my only alternative to write a recursive stored procedure?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:47:39+00:00Added an answer on May 17, 2026 at 3:47 pm

    Referring to :-

    1. In order to better understand my situation and SQL, why aren’t these clauses allowed?

    Based on my understanding of CTE’s, the whole idea behind creating a CTE is so that you can create a temporary result-set and use it in a named manner like a regular table in SELECT, INSERT, UPDATE, or DELETE statements.

    Because a CTE is logically very much like a view, the SELECT statement in your CTE query must follow the same requirements as those used for creating a view. Refer **CTE query definitions* section in following link on MSDN

    Also, because a CTE is basically a named resultset and it can be used like any table in SELECT, INSERT, UPDATE, or DELETE statements, you always have the option of using the various operators you mentioned when you use the CTE in any of those statements.

    With regarding to

    2.If I need to do some sort of recursion using some of these clauses, is my only alternative to write a recursive stored procedure?

    Also, I am pretty sure that you can use at least some of the keywords that you have mentioned above in a view / CTE select statement. For Example: Refer to the use of GROUP BY in a CTE here in the Creating a simple common table expression example

    Maybe, if you can provide a sample scenario of what you are trying to achieve, we can suggest some possible solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently learned about endianness and am still having difficulty identifying problem areas. Here
I have recently learned, that in MATLAB, the ! mark runs the code in
I've recently learned like 3 new languages and I'm starting to get them confused.
This is the sanitization function used in a book I recently learned from -
Today Recently on Stackoverflow i learned that: reintroduce is used to hide ancestor constructors
Recently i've switched to PHP 5.3+ and after that migration i learned that the
I've been building an app recently that has a model Books that is a
I've starting programming on ASP.NET MVC Framework a year ago. Recently. I've learning Ruby
Recently, I read this article: http://download.oracle.com/javase/tutorial/extra/generics/wildcards.html My question is, instead of creating a method
I've been a .Net developer and a Java developer and TBH I liked .Net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.