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

Getting values from row with the largets id

One way that I determine the most recent insertion into a table is to
get the highest id value in the id field. Using the auto increment
function whenever a new record is inserted in the table, the hightest
id number by default is the most recent submission into this table.

I would like to create a query that pulls up all the data from the row
with the highest id number. I know that to get that number, I can use
the max(id) approch, but I don't know how to enter this into a sql
statement, and get the other values that attach to it. I tried "select
name from table where id=max(id) but I get a group error reply.

What can I do to get the values I'm looking for?

Thanks,
Bill
Jul 19 '05 #1
3 1297
Frank wrote:
What can I do to get the values I'm looking for?


# Easy way
select name from table order by id desc limit 1;

# or using some programming language:
select max(id) from table;
// Save result id to variable max_id
select name from table where id=max_id;

# or if you have MySQL >= 4.1, you can use subqueries:
select name from table where id in(select max(id) from table);
Jul 19 '05 #2
Frank wrote:
What can I do to get the values I'm looking for?


# Easy way
select name from table order by id desc limit 1;

# or using some programming language:
select max(id) from table;
// Save result id to variable max_id
select name from table where id=max_id;

# or if you have MySQL >= 4.1, you can use subqueries:
select name from table where id in(select max(id) from table);
Jul 19 '05 #3
Frank wrote:
What can I do to get the values I'm looking for?


# Easy way
select name from table order by id desc limit 1;

# or using some programming language:
select max(id) from table;
// Save result id to variable max_id
select name from table where id=max_id;

# or if you have MySQL >= 4.1, you can use subqueries:
select name from table where id in(select max(id) from table);
Jul 19 '05 #4

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

Similar topics

0
by: Frank | last post by:
One way that I determine the most recent insertion into a table is to get the highest id value in the id field. Using the auto increment function whenever a new record is inserted in the table, the...
3
by: Jen | last post by:
Hi I have created some controls (HtmlInputText, HtmlGenericControl, TextBox) dynamically. But I have problem getting the values from these controls to save them. Is there a way to do that? ...
1
by: MattB | last post by:
OK, never mind my last post. It was easy enough to refer to the table the repeater is bound to, but I made a big, incorrect assumption in that post. In my last post I thought I was successfully...
7
by: kimmelsd33 | last post by:
I am using VB6. I want to read a tab delimited file, and assign each column value into a variable. If the variable is "-999.25", I want to make it a "0". I then want to reassemble the values, and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.