问题
Please bear with me as I am new to all this.
My query is, I have the following table and I am attempting to retrieve the most recent NOTE_PAD.NOTE_TEXT against the order. Example of how the table looks like is below.
The data in the below table is obtained from joining two separate tables. I have used the following syntax for the join and retrieved only a specific order number for this example (867318) as there are many orders in the data base.
Not certain if I’ve made it clear enough, but if not let me know if there is any specific information needed and I will try my best to provide. As mentioned please bear with me as I am totally new to this
SQL Syntax:
SELECT ORDER_TYPE,
ORDER_NUMBER,
ORDER_LINE,
NOTE_PAD.CREATED_DATE
FROM ORDER_AWB INNER JOIN
NOTE_PAD
ON ( "ORDER_AWB"."NOTES" = "NOTE_PAD"."NOTES" )
WHERE ( "ORDER_AWB"."ORDER_NUMBER" = '867318' )
Example of table result when above syntax is used:
回答1:
For an Oracle DB pre 12c this should work
SELECT * FROM
(
SELECT ORDER_TYPE,
ORDER_NUMBER,
ORDER_LINE,
NOTE_PAD.CREATED_DATE
FROM ORDER_AWB INNER JOIN
NOTE_PAD ON ( "ORDER_AWB"."NOTES" = "NOTE_PAD"."NOTES" )
WHERE ( "ORDER_AWB"."ORDER_NUMBER" = '867318' )
ORDER BY NOTE_PAD.CREATED_DATE DESC
)
WHERE ROWNUM <= 1
回答2:
From having a quick google it looks like the TRAX software it's using Oracle. If it's version 12c (12.1) or later and you're only looking to query one order at a time then putting this onto the end of your query should work
ORDER BY NOTE_PAD.CREATED_DATE DESC
FETCH NEXT 1 ROWS ONLY;
来源:https://stackoverflow.com/questions/34767708/retrieve-the-most-recent-row-pre-oracle-12c