473,765 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Max of a column where ...

Ike
How can I select , for a given name, that record with the highest id for
something like:

id INTEGER(11) PRIMARY KEY NOT NULL AUTO_INCREMENT
name VARCHAR(40)

I want to select the highest id where name='something '. I've tried along the
lines of:

select MAX(id) as id where name='something '

but with no success.

I know this is oversimplified -Ive stripped it down here intentionally to
try to determine how you select for a given row where a particular integer
value is the max value. Thanks, Ike
Feb 17 '06 #1
2 1748
Ike
needs to have "Group by id"

"Ike" <rx*@hotmail.co m> wrote in message
news:I8******** ******@newsread 2.news.atl.eart hlink.net...
How can I select , for a given name, that record with the highest id for
something like:

id INTEGER(11) PRIMARY KEY NOT NULL AUTO_INCREMENT
name VARCHAR(40)

I want to select the highest id where name='something '. I've tried along the lines of:

select MAX(id) as id where name='something '

but with no success.

I know this is oversimplified -Ive stripped it down here intentionally to
try to determine how you select for a given row where a particular integer
value is the max value. Thanks, Ike

Feb 18 '06 #2
Ike wrote:
How can I select , for a given name, that record with the highest id for
something like:

id INTEGER(11) PRIMARY KEY NOT NULL AUTO_INCREMENT
name VARCHAR(40)

I want to select the highest id where name='something '. I've tried along the
lines of:

select MAX(id) as id where name='something '

but with no success.

I know this is oversimplified -Ive stripped it down here intentionally to
try to determine how you select for a given row where a particular integer
value is the max value. Thanks, Ike


not sure of your "exact" syntax, understanding your data is paramount. It may
be giving you the correct information for what you asked...

Given:

mysql> select * from a;
+------+------+------+
| a | b | c |
+------+------+------+
| 1 | 2 | a |
| 2 | 2 | b |
| 3 | 2 | c |
| 4 | 2 | a |
| 5 | 2 | b |
| 6 | 2 | c |
| 7 | 2 | a |
| 8 | 2 | b |
| 9 | 2 | c |
| 10 | 2 | a |
| 11 | 2 | b |
| 12 | 2 | c |
+------+------+------+
12 rows in set (0.02 sec)

mysql> select max(a) from a where c='b';
+--------+
| max(a) |
+--------+
| 11 |
+--------+
1 row in set (0.00 sec)

mysql> select b,max(a) from a where c='b' group by b;
+------+--------+
| b | max(a) |
+------+--------+
| 2 | 11 |
+------+--------+
1 row in set (0.01 sec)

mysql> select b,max(a) from a where c='b';

ERROR 1140: Mixing of GROUP columns (MIN(),MAX(),CO UNT()...) with no GROUP
columns is illegal if there is no GROUP BY clause

You only need a GROUP BY statement if you are selecting other columns in
addition to the "functioned " column

--
Michael Austin.
DBA Consultant
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Feb 18 '06 #3

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

Similar topics

5
5296
by: nimdez | last post by:
Hi, I am working on an existing code base in which a lot of data displayed to the user is formatted in tables. Most tables are printed row-by-row using printf() with "%s" print conversion specification for each column (e.g. printf(%10s %25s %15s\n", pszCol1, pszCol2, pszCol3)). My problem is that when a string is longer the column's width, it overflows the column and takes the table out of alignment. What I want it to do is word-wrap...
4
4965
by: perspolis | last post by:
I have 3 columns in my datatabel name Total,unit,Price. I use a column expression in my project..and in this expression i multiplied two column... for example MyTable.Columns.Expression="Price*Unit"; but when i want to update my datatable an exception arise and says can not update computed column...:( how can i do this???
6
3248
by: Robert Schuldenfrei | last post by:
Dear NG, After being away from C# programming for a spell, I am trying my hand at what should be a simple task. I have been hitting my head against the wall this morning. I have a simple order entry application. The code below gets line items from a SQL Server database and returns them to a datagrid by way of a DataTable called lineTable. As long as I am just displaying columns in the SQL database everything works well. I now want...
19
25466
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to sort columns based on the column header the user has clicked in both Ascending and Descending formats.
6
10680
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the data on the datasource. It simply gets the first name and last name of an instructor and displays it in the grid. I have two major problems.... One, it doesn't display in the column until the row is saved, (Even after calling a refresh on the...
2
3951
by: ricky | last post by:
Hello, If anyone could help me with this I would highly appreciate it. I've tried everything and nothing works. What I am trying to do is so damn basic and it's just frustrating that it seems there's no support for this. Either that or I'm doing something wrong. Well, enough venting, here's what I need. Using this sample XML file (test.xml):
3
3544
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I can get this to work; however, the column header on the datagrid is not a link/sortable. What am I missing? Thanks in advance.
4
10696
by: Steph. | last post by:
I have a List view displaying data in Detail mode with several columns. How I can get the column index the user clicked on ? (when user click on an item inside the ListView, not on a column hearder..) Thanks for any help !
4
4916
by: Peter Gibbs | last post by:
I need some help with this problem. I'm using Access 2002 with XP. My problem is with a 2-column listbox. My VBA code puts text data into the listbox. The problem is that the text data ocasionally includes commas (,) and full-stops (.) - and when the data is placed in a column, Access confuses the punctuation within the text with delimiters and splits the text across columns.
2
11984
by: Frank | last post by:
I could use your help. I need to add tooltips to each column of an HTML table, for the entire column of cells. I want to add a single element to the table, and have that one element represent the tooltip for all the cells in the column. I'm doing the brute-force method right now of adding a tooltip to every <tdin the table. The problem there is that the HTML is ballooning in size as a result (see an example below). Any ideas,...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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
10164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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...
0
8833
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
7379
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...
1
3926
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
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.