473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Advanced Sorting SQL command

Hi there,

If we have a student score table with the names of 5 students and their
marks in two exams:

+--------+-------+-------+
| Name | Mark1 | Mark2 |
+--------+-------+-------+
| John | 10 | 8 |
| George | 7 | 2 |
| Paul | 3 | 6 |
| Nick | 9 | 6 |
| Adam | 4 | 8 |
+--------+-------+-------+

I want to order the entries, according to the WORST of the two marks of
each of the students. IE:

+--------+-------+-------+------------+
| Name | Mark1 | Mark2 | Worst Mark |
+--------+-------+-------+------------+
| John | 10 | 8 | 8 |
| Nick | 9 | 6 | 6 |
| Adam | 4 | 8 | 4 |
| Paul | 3 | 6 | 3 |
| George | 7 | 2 | 2 |
+--------+-------+-------+------------+

Of course, I do not really want the "Worst Mark" column (that is just
to show you, on what criteria I want the sorting).

I would be indebted if you could suggest any SQL command for this
advanced sorting.

Thanks in advance.

Asteras

Jul 23 '05 #1
2 2245
Asteras (as*****@gmail.com) wrote:
: Hi there,

: If we have a student score table with the names of 5 students and their
: marks in two exams:

: +--------+-------+-------+
: | Name | Mark1 | Mark2 |
: +--------+-------+-------+
: | John | 10 | 8 |
: | George | 7 | 2 |
: | Paul | 3 | 6 |
: | Nick | 9 | 6 |
: | Adam | 4 | 8 |
: +--------+-------+-------+

: I want to order the entries, according to the WORST of the two marks of
: each of the students. IE:

: +--------+-------+-------+------------+
: | Name | Mark1 | Mark2 | Worst Mark |
: +--------+-------+-------+------------+
: | John | 10 | 8 | 8 |
: | Nick | 9 | 6 | 6 |
: | Adam | 4 | 8 | 4 |
: | Paul | 3 | 6 | 3 |
: | George | 7 | 2 | 2 |
: +--------+-------+-------+------------+
In mysql

select * from student_score_table order by least(Mark1,Mark2);

--

This space not for rent.
Jul 23 '05 #2
Dear Malcolm,

Thank you very much for your advice. It worked perfectly.

Best Regards,

Ioannis

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Paul | last post by:
Hi all I have a sorting problem, but my experience with Python is rather limited (3 days), so I am running this by the list first. I have a large database of 15GB, consisting of 10^8 entries...
12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
2
by: Aravind | last post by:
Hi folks. I have a form, frmHistory, which has 4 command buttons: Sort Title (cmdSortTitle), Sort Name (cmdSortName), Due Today (cmdDueToday), and Due List (cmdDueList). Sort Title and Sort...
4
by: Mark Travis | last post by:
Hi all, I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid. To Digress ======= Development information about the page is as follows 1....
2
by: saleek | last post by:
Hi, I am trying to figure out why my datagrid has stopped firing the page and sort commands. Scenario: I originally had template columns in my datagrid and had set up custom bi-directional...
6
by: Dennis Gearon | last post by:
This is what has to be eventually done:(as sybase, and probably others do it) http://www.ianywhere.com/whitepapers/unicode.html I'm not sure how that will affect LIKE and REGEX. ...
0
by: Dorte | last post by:
Hi, I use the gridview control to display data. I use a dataadapter to fill a datatable from an SQL server - the command is a stored procedure. Furthermore I have a couple of template columns...
5
by: yefei | last post by:
In my web design, I display records from a SQL DataBase according to some filters the GridView is defined with select commands and selest parameters however, I also want to display all records...
1
by: dorandoran | last post by:
The sort on the childgrid is not working; nothing happens when I click on the each column header for sort. (I followed Satay's sample: http://www.codeproject.com/KB/aspnet/EditNestedGridView.aspx)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.