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

  • SEARCH
  • Home
  • 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 8356783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:17:07+00:00 2026-06-09T10:17:07+00:00

Writing my first nested SELECT statement and I’m hoping someone can help me out.

  • 0

Writing my first nested SELECT statement and I’m hoping someone can help me out.

I need to grab the CompanyCode and AgentId from the UniqueAgentIdtoUniqueAgentId table. However, I only need the ones that show up in a query from another table. The common link between the rows will the the UniqueAgentId column (basically I need to grab the CompanyCode and AgentId from the rows that contain the same UniqueAgentId as come up in the nested query).

When I write this query out, I get the extremely helpful message

Incorrect syntax near ‘)’

Query:

SELECT 
    CompanyCode, AgentId
FROM 
    UniqueAgentIdToUniqueAgentId un
WHERE 
    un.UniqueAgentId = 
       (SELECT UniqueAgentId 
        FROM 
            (SELECT q.LastChangeDate, a.UniqueAgentId 
             FROM QueueUpdates q, AgentProductTraining a 
             WHERE a.LastChangeDate >= q.LastChangeDate)
       )

EDIT
Thank you very much for the responses. Using every single query below, however I keep getting the same error message: Invalid object name ‘UniqueAgentIdToUniqueAgentId’. This is odd to me because this is an actual table on the database that SQL Management Studio can see.

SECOND EDIT
This turned out to simply be a spelling error. The new error is “The conversion of the varchar value ‘3030111101’ overflowed an int column.” Not quite sure what this means either…

FINAL EDIT
I was attempting to compare a char with an it, which caused this error. Thanks again for all the help!

  • 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-06-09T10:17:09+00:00Added an answer on June 9, 2026 at 10:17 am

    When you have a subquery in many databases, you need to give it an alias:

    SELECT CompanyCode, AgentId
    FROM UniqueAgentIdToUniqueAgentId un
    WHERE un.UniqueAgentId = 
          (SELECT UniqueAgentId 
           FROM (SELECT q.LastChangeDate, a.UniqueAgentId 
                 FROM QueueUpdates q, AgentProductTraining a 
                 WHERE a.LastChangeDate >= q.LastChangeDate
                ) t
          )
    

    However, your inner query might return multiple values, and you don’t need two nested queries:

    SELECT CompanyCode, AgentId
    FROM UniqueAgentIdToUniqueAgentId un
    WHERE un.UniqueAgentId in
          (SELECT UniqueAgentId 
           FROM QueueUpdates q, AgentProductTraining a 
           WHERE a.LastChangeDate >= q.LastChangeDate
          )
    

    And, it is more proper to use JOIN syntax in this case:

    SELECT CompanyCode, AgentId
    FROM UniqueAgentIdToUniqueAgentId un
    WHERE un.UniqueAgentId in
          (SELECT UniqueAgentId 
           FROM QueueUpdates q join
                AgentProductTraining a 
                on a.LastChangeDate >= q.LastChangeDate
          )
    

    That should help.

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

Sidebar

Related Questions

I am writing my first APK and I need some help. I find myself
I'm writing my first extbase extension for TYPO3 with nested models at the moment.
I am writing my first dual app and cannot figure out how to give
I am writing my first FireFox extension and I have some questions. Maybe someone
I'm writing my first client/server android app, and need an advice regarding server architecture.
Writing my first silverlight application. I need to deliver some bitmap that the customer
Writing my first C# application...never touched the language before and not much of a
I'm writing my first Rails app and I'm confused by a method call that
I'm writing my first batch file, and as I've never used Windows Command Line
i'm writing my first MATLAB O-O application and i'm confused about the implementation of

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.