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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:00:41+00:00 2026-05-23T18:00:41+00:00

table one: field one field two 1 1-1 2 1-2 3 1-5 4 1-3

  • 0

table one:

field one     field two
1               1-1
2               1-2
3               1-5
4               1-3
4               1-6
4              1-2
5              1-0

using the sql command to get the results as the following table.

field one     field two
5               1-0
1               1-1
2               1-2
4               1-2
4               1-3
4               1-6
3               1-5

ps: the condition is selecting field two order by asc . but if the result have the same field one.then put the field two together. and asc them.

  • 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-23T18:00:42+00:00Added an answer on May 23, 2026 at 6:00 pm

    Haven’t checked the syntax but something along these lines should do it:

    select tableOne.fieldOne, tableOne.fieldTwo, b.SortField from tableOne
    inner join 
    (select fieldOne, min(fieldTwo) as SortField from tableOne group by fieldOne) b
    on (b.fieldOne = tableOne.fieldOne)
    order by b.SortField, tableOne.fieldOne, tableOne.fieldTwo
    

    In essence: for each fieldOne find the lowest value in the group and use that as primary sortfield for all records in the group. Within the group sort on the actual value in fieldtwo

    There are still potential issues left though: 1-10 will sort between 1-1 and 1-2
    If you also want to resolve that you need to split up fieldtwo and convert to ints.

    In all cases you might want to rethink if this datamodel is really setup the way you want/need

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

Sidebar

Related Questions

I need to get two fields from a database table (retrieved using linq-to-sql), one
I am using SQLite Database and in one my table has field purchased_date (TEXT
I'm simply trying to get data from two sql server db tables using ado.net
I'm using dtsx in data migration between two SQL Server instance. One of the
I have two fields in a table. One contains values such as BTA, BEA,
I have a table with one field that can point to a foreign key
I want to add expire TIMESTAMP in DB table. I have one field timestamp
I have one table view that should be filtered by values of search field
I want to search a table to find all rows where one particular field
In one of the ms-access table I work with we have a text field

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.