473,441 Members | 2,052 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,441 software developers and data experts.

Products with Last PurchaseID

Hello ,

I would like to ask a question concerned with SQL Server 2000 query.
I've got a table PurchaseDetails and I would like to query from it.
I want all product records with last purchase ID. The following is my query statements.
SELECT MAX(PurchaseID) AS LastID, ProductID, BatchNo
FROM PurchaseDetails
GROUP BY ProductID, BatchNo

When I run this query statements , I got all products and all records (i.e. not only last PurchaseID but also old PurchaseID). So please help me how to query as I want.
Mar 15 '10 #1
9 1317
yarbrough40
320 100+
...I want all product records with last purchase ID...
I don't understand this. Do you mean you want all products where the PurchaseID field has a value in it? please explain with more detail.
Mar 15 '10 #2
Purchase Deatails Table includes the following fields.

PurchaseDetailsID
PurchaseID
ProductID
BatchNo
Quantity
Price
Amount

here sample data



200 100 20 100 A10000
201 101 20 120 B10001
202 102 20 50 D01111

I would like to get product with Last Purchase ID as below.

102 20 50 D01111
Mar 16 '10 #3
yarbrough40
320 100+
Assuming that your PurchasID is a numeric field

Enjoy!
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 1 * From PurchaseDetails ORDER BY PurchaseID DESC
Mar 16 '10 #4
Thanks yarbrough. But it return only one row and include one product.
Mar 16 '10 #5
yarbrough40
320 100+
I would like to get product with Last Purchase ID as below.

102 20 50 D01111
all you asked for was a single record (see your quote above). Please explain better what you are trying to do. I can't read your mind my friend.
Mar 16 '10 #6
I am sorry friend. I need in such a hurry. So I forgot to tell u what I really want. In fact I need all products(i.e. all products with last PurchaseID) from table. The one I show you is an example for product ID 20 and I have got about 100 product IDs.
Thanks for your patience.
Mar 16 '10 #7
yarbrough40
320 100+
so let me help to clarify.. tell me if I am correct ok? You have this table "PurchaseDetails" and in this table is a column called "PurchaseID". This PurchaseID field is numeric. There are multiple records that have the same PurchaseID number. What you would like is to return all records in this table with the largest PurchaseID number (don't say "last"... say "largest" because I have no idea what you mean by "last").

is this what you want?



-or is this more accurate.......

Every PurchaseID number is unique and they incriment (get larger) as more records are added. What you want is to find that largest PurchaseID number, then find what ProductID that it is associated with, then return all records with that same ProductID.

???????
Mar 16 '10 #8
Yes friend. PurchaseID is numeric field and there are multiple records with same PurchaseID. I would like to get largest PurchaseID for each ProductID.
Mar 17 '10 #9
yarbrough40
320 100+
Expand|Select|Wrap|Line Numbers
  1. SELECT Max(PurchaseID) AS LargestPurchaseID, ProductID
  2. FROM PurchaseDetails
  3. GROUP BY ProductID; 
Mar 17 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: frizzle | last post by:
Hi there I have a products site with a mysql backend. I have two tables: 1 with series, 1 with products belonging to certain series. Series looks like: - id - kind
2
by: Hohn Upshew | last post by:
I need some help to build a report enumerating the products in descending order depending on the sum of liters. In this way i can view the top products sold for a given period.But i fail to do...
6
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
44
by: Christoph Zwerschke | last post by:
In Python, it is possible to multiply a string with a number: >>> "hello"*3 'hellohellohello' However, you can't multiply a string with another string: >>> 'hello'*'world' Traceback (most...
24
by: Rob R. Ainscough | last post by:
I was reading yet another book on .NET - VB 2005 Professional (wrox) and read the statement; "Microsoft has staked their future on .NET and publicly stated that henceforth almost all their...
17
by: IanIpp | last post by:
We have a 3 month old quad processor/dual core server running SQL Server 2005 and already it is getting close to hitting the CPU wall. An 8 way CPU box is prohibitively expensive and out of the...
1
by: Bruce One | last post by:
I am evaluating some products to buy and increment our productivity. DevExpress seems to have good products. Actually we already XtraReports license. Who araound here uses some of their products?...
9
by: Earl | last post by:
I have somewhat of an interesting scenario: The form allows the user to select a service, which populates a a grid of product information related to that service ("service grid"). The user can...
3
by: robjh | last post by:
Hi there! :) I am doing a school project in Microsoft Access, but I am having trouble setting up one of my queries.... The two relevant tables are "Products" and "Purchases" Products...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.