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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:04:06+00:00 2026-06-03T01:04:06+00:00

Suppose I have a table NAME with the columns PART_TYPE and VALUE. Each type

  • 0

Suppose I have a table NAME with the columns PART_TYPE and VALUE. Each type can have multiple types like FAMILY, GIVEN, PREFIX, etc.

What I would like to do is write SQL to get all the names but have them first ordered by a specific type then have them ordered alphabetically within that type.

I have something like this:

SELECT *
FROM name
ORDER BY (
  CASE
    WHEN PART_TYPE = 'GIV'
    THEN VALUE
  END)

But I’m not sure how to include the other types as a primary order while keeping the VALUE as the secondary order. Adding another case statement will then just make VALUE the primary order.

I would like to keep this database independent but if need be, I would be willing to make it Oracle specific.

How can I do this? Also, a way of doing this with Hibernate Criteria would also be greatly appreciated.

Edit: I need the PART_TYPE to be ordered by a specific order as defined by me. In particular, it needs to be GIVEN then FAMILY.

So it should look like this:

GIVEN  A
GIVEN  B
GIVEN  C
FAMILY A
FAMILY B

The natural order by would have FAMILY first, not GIVEN.

  • 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-03T01:04:08+00:00Added an answer on June 3, 2026 at 1:04 am

    The most manageable way of resolving this is probably to have a table containing all your Types, and then a sort column within that. So you might have a table like:

    TypeID      Name      SortOrder
    1           FAMILY    2
    2           GIVEN     1
    3           PREFIX    3
    

    Then you Can join this on to your query and use:

    ORDER BY SortOrder, Value
    

    You could just resolve this with a CASE expression

    ORDER BY CASE Type
                WHEN 'GIVEN' THEN 1
                WHEN 'FAMILY' THEN 2
                WHEN 'PREFIX' THEN 3
                END,
                Value
    

    But the more types you have the less manageable the case expression becomes.

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

Sidebar

Related Questions

Suppose we have a table which holds information about person. Columns like NAME or
Suppose I have a table with columns Name VARCHAR, Department VARCHAR, Gender VARCHAR, and
Suppose i have the following table book ----- id name genre check_out_date location_id Can
Suppose I have a table: ACCOUNT It has columns: ID , NAME , BALANCE
I have a table called Employee (with columns like name, ssn, age , etc..)
Suppose you have these tables: Table Name: Salesman Fields: S_ID(Primary Key), Name Table Name:
Suppose i have a mysql table name table with fields rank date id The
Suppose I have a table with the following rows id Name Price Supplier 1
Suppose I have table A with a field that can be either 1 or
Suppose I have a table like: create table { id numeric(5,3), code varchar(10) }

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.