Jump to content

Ordering A Select Statement By Primary And Secondary Columns


Greywacke

Recommended Posts

hi there,i am using MySQL, and trying to process the following select statement:

SELECT 	10_serviceprospects.bigint_ProspectID, 	5_suppliers.text_SupplierName, 	5_suppliers.text_ContactFirstName, 	5_suppliers.text_ContactSurname, 	5_suppliers.text_ContactPosition, 	5_suppliers.`text_ContactE-mail`, 	5_suppliers.bigint_ContactTel, 	13_prospectleadsent.timestamp_Sent, 	12_prospectmessages.smallint_ProspectMessageCount FROM 	13_prospectleadsent, 5_suppliers, 12_prospectmessages, 10_serviceprospects WHERE 	13_prospectleadsent.bigint_SupplierID = 5_suppliers.bigint_SupplierID AND 	13_prospectleadsent.bigint_MessageID = 12_prospectmessages.bigint_MessageID AND 	13_prospectleadsent.bigint_ProspectID = 10_serviceprospects.bigint_ProspectID AND 	13_prospectleadsent.bigint_ProspectID = 1 ORDER BY 	12_prospectmessages.smallint_ProspectMessageCount ASC, 	5_suppliers.text_SupplierName ASC;

however, they only seem to order by the 12_prospectmessages.smallint_ProspectMessageCount field. how can i make them order like i attempted to here, with a primary and secondary order? the correct fields are returned, just in the wrong order...someone please help!

Link to comment
Share on other sites

Have you tried outputting 12_prospectmessages.smallint_ProspectMessageCount? It may reveal why it's not ordering the results correctly. Can you provide some minimal data sample where this problem occurs?

Link to comment
Share on other sites

nevermind, sighs... this issue has been resolved :)here is the correct select statement :)

SELECT 	10_serviceprospects.bigint_ProspectID, 	5_suppliers.text_SupplierName, 	5_suppliers.text_ContactFirstName, 	5_suppliers.text_ContactSurname, 	5_suppliers.text_ContactPosition, 	5_suppliers.`text_ContactE-mail`, 	5_suppliers.bigint_ContactTel, 	13_prospectleadsent.timestamp_Sent, 	12_prospectmessages.smallint_ProspectMessageCount FROM 	13_prospectleadsent, 	5_suppliers, 	12_prospectmessages, 	10_serviceprospects WHERE 	13_prospectleadsent.bigint_SupplierID = 5_suppliers.bigint_SupplierID AND 	13_prospectleadsent.bigint_MessageID = 12_prospectmessages.bigint_MessageID AND 	13_prospectleadsent.bigint_ProspectID = 10_serviceprospects.bigint_ProspectID AND 	13_prospectleadsent.bigint_ProspectID = 1 ORDER BY 	5_suppliers.text_SupplierName ASC, 	12_prospectmessages.smallint_ProspectMessageCount ASC

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...