473,395 Members | 1,774 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,395 software developers and data experts.

Return Highest Record (SQL - Access)

I am building an app that is looking for the latest model of a
particular product. I am storing these results in a datalist. Below is
what the location and newest model fields look like:

Location - NewestModel

A1 - A
A1 - B
A2 - A
A3 - A
A3 - B
A3 - C
A4 - A
A5 - A
A5 - B
A5 - C
A5 - D
A5 - E

I know that I can do a SELECT MAX(NewestModel) to return the highest,
E, but it would defeat the purpose of what I am trying to do.

The output I am going for is:

A1 - B
A2 - A
A3 - C
A4 - A
A5 - E
This way the output shows what the latest version is at each location.
This is the way that the database is configured (it was like this when
I came on) so changing the layout and stored procedures is not an
option.

Any suggestions?

Nov 19 '05 #1
4 1504
Sparky Arbuckle wrote:
I am building an app that is looking for the latest model of a
particular product. I am storing these results in a datalist. Below is
what the location and newest model fields look like:

Location - NewestModel

A1 - A
A1 - B
A2 - A
A3 - A
A3 - B
A3 - C
A4 - A
A5 - A
A5 - B
A5 - C
A5 - D
A5 - E

I know that I can do a SELECT MAX(NewestModel) to return the highest,
E, but it would defeat the purpose of what I am trying to do.

The output I am going for is:

A1 - B
A2 - A
A3 - C
A4 - A
A5 - E
This way the output shows what the latest version is at each location.
This is the way that the database is configured (it was like this when
I came on) so changing the layout and stored procedures is not an
option.

Any suggestions?


Its not an ASP.NET thing, its a tSql thing...
I think you are looking for the GROUP BY clause

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
Nov 19 '05 #2
On 17 Aug 2005 12:17:34 -0700, "Sparky Arbuckle" <tw*@secureroot.com> wrote:
¤ The output I am going for is:
¤
¤ A1 - B
¤ A2 - A
¤ A3 - C
¤ A4 - A
¤ A5 - E
¤
¤
¤ This way the output shows what the latest version is at each location.
¤ This is the way that the database is configured (it was like this when
¤ I came on) so changing the layout and stored procedures is not an
¤ option.
¤
¤ Any suggestions?

Example of what Curt referred to:

http://www.techonthenet.com/sql/group_by.php
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 19 '05 #3
How would I go about hooking up another table to this and instead of
retrieving the max for NewestModel, have all the revisions to the new
model listed? I'll explain.
A1 - C
A2 - A
A3 - C
I am able to get those results with no problem using the following SQL
statement:
SELECT tblProduct.Location, tblProduct.ProductType,
tblProduct.ProductNumber, Max(tblProduct.NewestModel) As
MaxOfNewestModel FROM tblProduct WHERE tblProduct.Location = "A1" AND
(tblProduct.ProductType = "CD") GROUP BY tblProduct.Location,
tblProduct.ProductType, tblProduct.ProductNumber;
What if I wanted to bring in another table (tblRevision) and achieve a
result that is:
A1 - C - C1
C2
C3
A2 - A - A1
A3 - B - B1
B2
B3
B4
I have tried to simply add tblRevision.RevisionNumber to the SQL from
above but instead of the MAX NewestModel it is retrieving all of them.
Any suggestions?

Nov 19 '05 #4
On 18 Aug 2005 08:48:43 -0700, "Sparky Arbuckle" <tw*@secureroot.com> wrote:

¤ How would I go about hooking up another table to this and instead of
¤ retrieving the max for NewestModel, have all the revisions to the new
¤ model listed? I'll explain.
¤
¤
¤ A1 - C
¤ A2 - A
¤ A3 - C
¤
¤
¤ I am able to get those results with no problem using the following SQL
¤ statement:
¤
¤
¤ SELECT tblProduct.Location, tblProduct.ProductType,
¤ tblProduct.ProductNumber, Max(tblProduct.NewestModel) As
¤ MaxOfNewestModel FROM tblProduct WHERE tblProduct.Location = "A1" AND
¤ (tblProduct.ProductType = "CD") GROUP BY tblProduct.Location,
¤ tblProduct.ProductType, tblProduct.ProductNumber;
¤
¤
¤ What if I wanted to bring in another table (tblRevision) and achieve a
¤ result that is:
¤
¤
¤ A1 - C - C1
¤ C2
¤ C3
¤ A2 - A - A1
¤ A3 - B - B1
¤ B2
¤ B3
¤ B4
¤
¤
¤ I have tried to simply add tblRevision.RevisionNumber to the SQL from
¤ above but instead of the MAX NewestModel it is retrieving all of them.
¤ Any suggestions?

Sounds like you need to do a JOIN. You may want to repost this question to
microsoft.public.framework.ado.net.
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
2
by: Megan | last post by:
Hi everybody- I have 2 tables, Hearings and Rulings. Both have primary keys called, CaseID, that are autonumbers. I don't want both tables to have the same autonumber. For example, if Hearings...
2
by: David C. Barber | last post by:
upsized an MDB to ADP/SQL Server 2000 under Access 2000. All the DAO code that I've changed to ADO code is working fine, HOWEVER the form Record Source itself does not seem willing to return data....
2
by: Dirtyweeker | last post by:
Hi, I have a database which records fitness test results of pupils. There are the usual name fields and then a series of fields holding results, e.g. field BP1 and field BP2; each of these...
33
by: Steven Taylor | last post by:
Hope someone can help. This is half an Access question. The half I'm using is Access Xp as a backend data file. I'm using ODBC to connect to the data file. All commands are via SQL type...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
by: Jon Turlington | last post by:
When in access the SQL Statement works as expected; in ADO it does not. I have replaced the * with the % so I am sure that's not the problem. Anyone have any idea? <% Dim objConn, objRS,...
5
by: owz | last post by:
Hi again had some more problems, all help welcome. Access 2000, SQL My problem is as stated in the title. I want 2 display the highest and lowest priced car sold for this month. This is what I...
1
by: Coll | last post by:
Hi - I'm trying to figure out how to append a record to a table and then open a form and display that record. My thought was to use the autonum primary key field (recordnum) and display the highest...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
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...
0
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,...

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.