SQL Syntax quickie

2003-10-25 Thread dan
Hi, I've looked around to not much avail, what I'm looking for is a SELECT query that selects the last record in a database. Each table has the primary field "id", to which auto increments on each input. I don't want to have to load the entire db, cycle through it until I find the last one, the pr

Re: SQL Syntax quickie

2003-10-25 Thread Wiggins d'Anconia
dan wrote: Hi, I've looked around to not much avail, what I'm looking for is a SELECT query that selects the last record in a database. Each table has the primary field "id", to which auto increments on each input. I don't want to have to load the entire db, cycle through it until I find the last

Re: SQL Syntax quickie

2003-10-25 Thread Tore Aursand
On Sat, 25 Oct 2003 10:43:51 +0100, dan wrote: > Basically what happens is the program enters information using INSERT, and > then it needs to re-read the data it's just sent to verify it, and get the > id number that auto_increment assigned it. You don't say anything about what RDBMS you're using

RE : SQL Syntax quickie

2003-10-25 Thread SIMON Cedric
Another solution : For your query, try "SELECT MAX(id) FROM table" That works with mysql. -Message d'origine- De : dan [mailto:[EMAIL PROTECTED] Envoyé : samedi 25 octobre 2003 11:44 À : [EMAIL PROTECTED] Objet : SQL Syntax quickie Hi, I've looked around to not

Re: RE : SQL Syntax quickie

2003-10-26 Thread Tore Aursand
On Sun, 26 Oct 2003 06:30:11 +0100, SIMON Cedric wrote: > For your query, try "SELECT MAX(id) FROM table" > That works with mysql. That should "work" with most databases, but what happens if there's a new insert between the original insert and the SELECT statement above? This _could_ be solved b

Re: RE : SQL Syntax quickie

2003-10-26 Thread Tore Aursand
On Sun, 26 Oct 2003 13:40:20 +, dan wrote: > The MAX(id) didn't return anything [...] Are you sure about that? Generally, MAX(id) _always_ returns something, ie: SELECT MAX(user_id) FROM user This one will return the highest 'user_id' value, _or_ 0 if there are no records in the 'user' ta

Re: RE : SQL Syntax quickie

2003-10-26 Thread dan
The MAX(id) didn't return anything, i eventually settled for an idea posted to SELECT id FROM memodata ORDER BY id DESC then take the first line value and ignore the rest. Ideally though i want the last line with the highest id number. I know for a fact that another INSERT won't happen before the S

Re: RE : SQL Syntax quickie

2003-10-27 Thread dan
Thanks I'll try your suggestion about the LIMIT portion, that's what I want, to minimize the amount of data the program gets from the SQL server, making processing faster. The program isn't a script as such that's executed from the web, it's a program that opens a socket, connects to IRC chat and

RE: RE : SQL Syntax quickie

2003-10-27 Thread EUROSPACE SZARINDAR
0 SQL> insert into table_id(id) values (1); 1 row created. SQL> select nvl(max(id), 0) from table_id; NVL(MAX(ID),0) -- 1 == Michel -Message d'origine- De: dan [mailto:[EMAIL PROTECTED] Date: dimanche 26 octobre 2003 14:40 À: [EMA

Re: RE : SQL Syntax quickie

2003-10-27 Thread Chuck Fox
d'origine- De : dan [mailto:[EMAIL PROTECTED] Envoyé : samedi 25 octobre 2003 11:44 À : [EMAIL PROTECTED] Objet : SQL Syntax quickie Hi, I've looked around to not much avail, what I'm looking for is a SELECT query that selects the last record in a database. Each table has the pri

Re: RE : SQL Syntax quickie

2003-11-12 Thread R. Joseph Newton
dan wrote: > The MAX(id) didn't return anything, Best check your data types, and syntax. Either ID is somehow a string value, or you are offering the wrong SQL syntax: mysql> describe test2; +-+-+--+-+-++ | Field | Type| Null | Key |