December 28, 2007 at 2:44 pm
I have a table with purchase order info. There are several records with the same p.o number but kept in sequence by a 'posuf' that may be either a 1 or 2 or 3 or 4. How do I select a record with just a 'posuf' that = 4. I want the entire record but only if it has a 'posuf' that = 4 and not 3,2 or 1.
Thanks.
December 28, 2007 at 2:48 pm
SELECT P.*
FROM PurchaseOrders AS P
INNER JOIN (
SELECT PurchaseOrderNumber, Max(Posuf) AS LastPosuf
FROM PurchaseOrders
GROUP BY PurchaseOrderNumber
) AS PM
ON P.PurchaseOrdernumber = PM.PurchaseOrdernumber
AND P.Posuf = PM.LastPosuf
December 28, 2007 at 3:11 pm
Huh? I must be missing something there...If you only want them if they have "4" for "posuf", then I'm thinking that you need to say that somewhere in the code.
SELECT p.*
FROM PurchaseOrders AS p
P.Posuf = 4
--Jeff Moden
Change is inevitable... Change for the better is not.
December 31, 2007 at 4:00 am
Jeff,
Concur.
SELECT p.*
FROM PurchaseOrders AS p
P.Posuf in (4)
Will also work. Am i correct ? Is there any difference between your code and my code ?
karthik
December 31, 2007 at 10:28 am
Yes... it works.
No, no difference to the sever.
Yes... difference in readability but depends on what you're used to. I prefer the use of "=" to "IN" for single value criteria mosty because it's 3 characters less to type
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy