CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2005
    Location
    algiers, Algeria
    Posts
    132

    [RESOLVED] access problem

    Hi, i have table with column that takes country name else it takes "other" value my question is how i can retrieve rows grouped by country name and the rows with country name equal to "other" are in the end of selection

  2. #2
    Join Date
    Dec 2006
    Posts
    203

    Re: access problem

    Quote Originally Posted by ledaker
    Hi, i have table with column that takes country name else it takes "other" value my question is how i can retrieve rows grouped by country name and the rows with country name equal to "other" are in the end of selection
    Easiest way would probably be

    Code:
    SELECT *
    FROM tableA
    WHERE columnA <> 'Other'
    ORDER BY columnA asc
    
    UNION
    
    SELECT *
    FROM tableA
    WHERE columnA = 'Other';
    Sincerely,

    Martin Svendsen

  3. #3
    Join Date
    Jun 2006
    Posts
    437

    Re: access problem

    Hi all.

    This query doesn't work beacause you cannot add the ORDER BY clause into UNION. Probably there isn't a way to get what ledaker wants using only a query.

  4. #4
    Join Date
    Dec 2005
    Location
    algiers, Algeria
    Posts
    132

    Re: access problem

    Quote Originally Posted by davide++
    Hi all.

    This query doesn't work beacause you cannot add the ORDER BY clause into UNION. Probably there isn't a way to get what ledaker wants using only a query.
    davide++ has reason this query doesnt work, please other solution

  5. #5
    Join Date
    Dec 2006
    Posts
    203

    Re: access problem

    Sorry, you're right, try this instead

    Code:
    SELECT *, '1' AS OrderBy
    FROM tableA
    WHERE columnA <> 'Other'
    
    UNION
    
    SELECT *, '2' AS OrderBy
    FROM tableA
    WHERE columnA = 'Other'
    
    ORDER BY OrderBy ASC;
    Just note that you'll get the extra field out "OrderBy" with values '1' or '2'.
    Sincerely,

    Martin Svendsen

  6. #6
    Join Date
    Dec 2005
    Location
    algiers, Algeria
    Posts
    132

    Re: access problem

    thank you

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