6 messages in com.mysql.lists.win32RE: Need Help With SQL Statement| From | Sent On | Attachments |
|---|---|---|
| Michael Avila | 11 Jul 2005 18:12 | |
| Sa...@ Inmagine | 11 Jul 2005 18:32 | |
| Leigh Sharpe | 11 Jul 2005 18:42 | |
| Michael Avila | 11 Jul 2005 18:45 | |
| Blue Wave Software | 12 Jul 2005 00:01 | |
| jbon...@sola.com.au | 13 Jul 2005 17:11 |
| Subject: | RE: Need Help With SQL Statement![]() |
|---|---|
| From: | Michael Avila (mav...@mich.com) |
| Date: | 07/11/2005 06:45:33 PM |
| List: | com.mysql.lists.win32 |
Thanks! Did not realize that sorts could be broken out like that. Thank you.
Mike
-----Original Message----- From: Sam @ Inmagine [mailto:sa...@inmagine.com] Sent: Monday, July 11, 2005 9:33 PM To: Michael Avila; MySQL - Win32 Subject: Re: Need Help With SQL Statement
Hi, Maybe you can try
SELECT * FROM sop ORDER BY sop_index ASC, sop_versionmajor DESC, sop_versionminor DESC, sop_versionfix DESC
Hope this works...
Sam
-----Original Message----- From: "Michael Avila" <mav...@mich.com> To: "MySQL - Win32" <win...@lists.mysql.com> Date: Mon, 11 Jul 2005 21:13:10 -0400 Subject: Need Help With SQL Statement
I can do basic SQL coding but I am having a hard time figuring this one out.
I have a table with the following fields.
CREATE TABLE sop ( sop_id bigint(12) NOT NULL auto_increment, certcode_code varchar(5) NOT NULL default '', sop_index int(5) NOT NULL default '0', sop_versionmajor int(3) NOT NULL default '0', sop_versionminor int(3) NOT NULL default '0', sop_versionfix int(2) NOT NULL default '0', sop_date date NOT NULL default '0000-00-00', sop_title varchar(35) NOT NULL default '', sop_text longtext NOT NULL, PRIMARY KEY (sop_id) )
The index is a number that acts like a catalog number in a library. There can be multiple occurrences of records with the same index number. The version information will determine which is the latest. The date is incidental to the other sequencing fields.
What I would like to do is create a SQL statement that will retrieve all of the latest versions for each index number. My thought was
SELECT * FROM sop ORDER BY sop_versionmajor, sop_versionminor, sop_versionfix DESC
That would bring the latest/newest versions to the top. But I want it in index order ASC. If I add sop_index to the ORDER BY I will have it in reverse order for printing. Or if I add ASC then I have to find the last version of each index.
Any ideas, suggestions, coding is GREATLY appreciated.
Thanks in advance.
Mike




