CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Posts
    206

    Question Trouble with Select Distinct() FROM Sub Select

    Hi,

    I'm using SQL Server 2005 and I'm having a bit of trouble with something that seems like it should be pretty simple.

    I have a table with 2 fields - AccountNo and Name. Neither field has to be unique.

    I want to get the number of distinct AccountNo where the Name begins with the letter a.

    Code:
    SELECT DISTINCT(AccountNo) FROM (SELECT AccountNo FROM Customers WHERE Name LIKE 'a%')
    The query fails and I get the message "Incorrect syntax near ')".

    I'm sure I'm doing something pretty stupid somewhere. Can anyone help me figure out what it it?

    Thanks,

    dlarkin77

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Trouble with Select Distinct() FROM Sub Select

    There is no need for the sub-query. You could just do this
    Code:
    SELECT Distinct AccountNo FROM Customers WHERE Name LIKE 'a%'

  3. #3
    Join Date
    Oct 2004
    Posts
    206

    Resolved Re: Trouble with Select Distinct() FROM Sub Select

    I'm embarrassed at how simple that is .

    Thanks very much Shuja Ali.

    I would rate your post but I have to spread some reputation around before I can so I'll get you sometime later.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured