473,597 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Products with Last PurchaseID

17 New Member
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 1323
yarbrough40
320 Contributor
...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
mikewin86
17 New Member
Purchase Deatails Table includes the following fields.

PurchaseDetails ID
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 Contributor
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
mikewin86
17 New Member
Thanks yarbrough. But it return only one row and include one product.
Mar 16 '10 #5
yarbrough40
320 Contributor
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
mikewin86
17 New Member
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 Contributor
so let me help to clarify.. tell me if I am correct ok? You have this table "PurchaseDetail s" 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
mikewin86
17 New Member
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 Contributor
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
1474
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
3117
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 it. In my query i have build a total as follows SELECT products.Productid, products.grade, products.size, Sum(.liters) AS SumOfliters, orders.invoicedate FROM products INNER JOIN ((affiliates INNER JOIN Customers ON
6
3090
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 the table, but I was not allowed to do that, because "there are records related with those PRODUCTS in other tables (e.g. in table "ORDER_DETAIL").
44
4160
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 recent call last): File "<interactive input>", line 1, in ?
24
1813
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 research and development will be done on this platform. It is expected that, eventually, almost all Microsoft products will be ported to the .NET platform." So I thought about this statement for a minute -- then I realized that I have ALL...
17
2631
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 question. I am looking desperately for a way to TRULY scale out SQL server...in the same way that IIS can be scaled out via App Center. The "in the box" solution for SQL Server 2005 scaling out is the DMV. Unfortunately this solution makes...
1
1338
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? What r the good and bad points? Thanks to all !!!
9
1468
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 then select from the products in the first grid and those choices populate the second "choices grid". The product grid is bound to a strongly-typed dataset table which can be filled in a couple of different ways. More on this shortly.
3
3634
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 Product ID Name Type
0
7894
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8392
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8046
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8262
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6711
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3938
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2410
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1500
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.