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 6383675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:40:44+00:00 2026-05-25T02:40:44+00:00

Warning, ugly query alert (MS SQL Server 2008): SELECT BaseDocs.* FROM ( SELECT ROW_NUMBER()

  • 0

Warning, “ugly” query alert (MS SQL Server 2008):

SELECT BaseDocs.* FROM (
  SELECT ROW_NUMBER() OVER (ORDER BY BaseDocs.DateUpdated DESC) AS Row, BaseDocs.* 
    FROM BaseDocs INNER JOIN DocCats ON BaseDocs.DocId = DocCats.DocId  
    WHERE DocCats.CatId IN (4) AND BaseDocs.BaseId = 1
  ) AS Paged 
  WHERE Row > 0 AND Row <=3

This query throws this error:

The column prefix ‘BaseDocs’ does not match with a table name or alias
name used in the query.

This query is against these tables:

BaseDocs Table
 - DocId PK
 - BaseId FK
 - ...

DocCategories Table
 - CatId PK
 - ...

DocCats (join) Table
 - DocId FK PK 
 - CatId FK PK

After “hacking” at this query for so long, I think my brain is frying… but it’s close, I can feel it. Thanks in advance!

  • 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-25T02:40:45+00:00Added an answer on May 25, 2026 at 2:40 am

    Just don’t specify a table alias in your SELECT – that table alias is visible only inside your subquery!

    SELECT *
    FROM 
       (SELECT 
            ROW_NUMBER() OVER (ORDER BY BaseDocs.DateUpdated DESC) AS Row, 
            BaseDocs.* 
        FROM BaseDocs 
        INNER JOIN DocCats ON BaseDocs.DocId = DocCats.DocId  
        WHERE 
             DocCats.CatId IN (4) 
             AND BaseDocs.BaseId = 1
      ) AS Paged 
    WHERE 
       Row > 0 AND Row <= 3
    

    or alternatively: use the alias given to your subquery:

    SELECT Paged.* .....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast and
I'm about to commit an ugly temporary hack in order to work around a
Warning on the line with journalComment.delegate = self: Assigning to 'id' from incompatible type
Warning - I am very new to NHibernate. I know this question seems simple
WARNING: I have been learning Python for all of 10 minutes so apologies for
(Warning - asp newbie) I have an aspx file with the tag <%@ Page
(Warning: Clueless Rails Newbie!) In my show.html.erb for my albums view, I call a
Warning acronym overload approaching!!! I'm doing TDD and DDD with an MVP passive view
Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/happy/public_html/source/imap/fet_mail_from_email_add.php on line 7 can't connect:
Warning: This is inherited legacy code that was initially put together in the early

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.