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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:17:33+00:00 2026-05-26T05:17:33+00:00

I’m using Oracle. My sql returns a column like this Name: John Smith David

  • 0

I’m using Oracle. My sql returns a column like this

Name:
John Smith
David Lee
…

If I do Order by Name, it will order by first name. How do I order by Last name? If I do Order by Lastname, Firstname oracle returns invalid identifiers. I tried substr, instr but it doesn’t work. I know the sql is tedious but just want the data to quickly fix this issue.

Full SQL:
http://pastebin.com/hYkdHBDM

  • 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-26T05:17:33+00:00Added an answer on May 26, 2026 at 5:17 am

    First, in order to sort by LastName, it needs to be one of the columns you return in each of the queries in your Union All. Second, you can greatly simplify your query by using a common-table expression. Third, do not use the comma delimited syntax for Joins (e.g. From TableA, TableB, TableC…). Instead use the ISO Join syntax.

    With RootQuery As
        (
        Select MeetingID
            , FirstName || ' ' || LastName AS Name
            , LastName
            , CASE WHEN RSVP = 1 THEN 1 ELSE NULL END AS Yes
            , CASE WHEN RSVP = 0 THEN 1 ELSE NULL END AS No
            , CASE WHEN RSVP = 2 THEN 1 ELSE NULL END AS Phone
            , CASE WHEN RSVP = -1 THEN 1 ELSE NULL END AS No_Reply
            , MysteryTable0.Response1
            , MysteryTable1.Response2
            , Note
            , groupname      
          From Attendance A
            Join Allusers As B
                And B.MemberId = A.PersonId
            Join MembershipGroups As M
                And M.MemberId = B.MemberID
            Join    (
                    SELECT TD.MEMBERID AS MEM0
                        , Response AS Response1
                    FROM TRACKINGDETAILS TD, ALLUSERS U
                    Where TD.MEMBERID = U.MEMBERID 
                        And TD.TRACKINGID = 64
                    ) MysteryTable0
                On MysteryTable0.Mem0 = B.MemberId
    
            Join    (
                    SELECT TD.MEMBERID AS MEM1
                        , Response AS Response2
                    FROM TRACKINGDETAILS TD, ALLUSERS U
                    Where TD.MEMBERID = U.MEMBERID 
                        And TD.TRACKINGID = 65
                    ) As MysteryTable1
                On MysteryTable1.Mem1 = B.MemberId
            Where Meetingid = :1
            )
    Select MeetingId, Name, LastName, Yes, No, Phone, No_Reply
        , Response1, Response2
        , Note, GroupName
    From RootQuery
    Union All
    Select Null, 'Total', LastName, SUM(Yes), SUM(No), SUM(Phone), SUM(No_Reply)
        , TO_CHAR(SUM(Response1))
        , TO_CHAR(SUM(Response2))
        , NULL, Groupname 
    From RootQuery
    Group By GroupName
    Union All 
    Select Null, 'Grand Total', LastName, SUM(Yes), SUM(No), SUM(Phone), SUM(No_Reply)
        , TO_CHAR(SUM(Response1))
        , TO_CHAR(SUM(Response2))
        ,NULL, ' '
    From RootQuery
    Group By ???
    Order By GroupName Desc, LastName Asc, Name Asc
    

    Btw, the last query will probably have a problem in that it did not have a Group By (which I denoted with Group By ???) but you are using aggregate functions.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
In order to apply a triggered animation to all ToolTip s in my app,
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.