Avatar billede trexy Nybegynder
16. februar 2004 - 17:37 Der er 4 kommentarer og
1 løsning

Se sidste indtasting

Jeg vil gerne se det sidste "ID" som er brugt i en af mine tabeller.
Hvordan gør man det?
Avatar billede arne_v Ekspert
16. februar 2004 - 17:40 #1
Hvis det er auto genereret så:

SELECT LAST_INSERT_ID()

hvis det er manuelt indtastet skal du have et kriterie at finde det på.
Avatar billede sth Novice
17. maj 2004 - 22:51 #2
Fik lige trykket lidt for hurtig
skulle have været: SELECT LAST_INSERT_ID() FROM tabel
SE:
http://dev.mysql.com/doc/mysql/en/Information_functions.html

The last ID that was generated is maintained in the server on a per-connection basis. This means the value the function returns to a given client is the most recent AUTO_INCREMENT value generated by that client. The value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that you can retrieve your own ID without concern for the activity of other clients, and without the need for locks or transactions. The value of LAST_INSERT_ID() is not changed if you update the AUTO_INCREMENT column of a row with a non-magic value (that is, a value that is not NULL and not 0). If you insert many rows at the same time with an insert statement, LAST_INSERT_ID() returns the value for the first inserted row. The reason for this is to make it possible to easily reproduce the same INSERT statement against some other server. If you use INSERT IGNORE and the record is ignored, the AUTO_INCREMENT counter still is incremented and LAST_INSERT_ID() returns the new value. If expr is given as an argument to LAST_INSERT_ID(), the value of the argument is returned by the function and is remembered as the next value to be returned by LAST_INSERT_ID(). This can be used to simulate sequences:


eller
se evt. http://www.eksperten.dk/spm/467742
Avatar billede arne_v Ekspert
18. maj 2004 - 07:12 #3
Øh.

Hvis man læser dit link så ser man netop at min syntax:

SELECT LAST_INSERT_ID()

er korrekt og at man ikke skal bruge din syntax:

SELECT LAST_INSERT_ID() FROM tabel

...
Avatar billede sth Novice
18. maj 2004 - 17:27 #4
øøøhhh ja hvad skete der lige her ! jeg tro at jeg har blandet 2 spørgsmål sammen, jeg beklager
Avatar billede trexy Nybegynder
04. juli 2004 - 11:39 #5
Lukker
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester