LAST_INSERT_ID()返回多行0? [英] LAST_INSERT_ID( ) returning multiple rows of 0?

查看:211
本文介绍了LAST_INSERT_ID()返回多行0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在在MyphpAdmin中工作,不知道我缺少什么:

Working in MyphpAdmin for now, not sure what I am missing:

order table strucure: p>

order table strucure:

OrderID     int(11)  auto_increment
CustomerID  varchar(50)  
BillAddr    varchar(200)  
ShipAddr    varchar(200)  
Date            date  
Total           double

4行数据,具有不同的OrderID。

The table currently has 4 rows of data, with different OrderIDs.

sql:

SELECT LAST_INSERT_ID() FROM `order`  

结果:

LAST_INSERT_ID()
0
0
0
0


b $ b

我期待第四行OrderID - 只有一个数字,但是MyphpAdmin中的每一行都有一个0。

I was expecting the fourth rows OrderID - just one number but got a 0 for each row in MyphpAdmin.

任何一个方向都是有用的, 谢谢。

Any point in the right direction is helpful, thank you.

推荐答案

LAST_INSERT_ID()返回最后一个插入行的ID,没有绑定到任何表。因此,如果您创建了一个新行:

LAST_INSERT_ID() returns the id of the last inserted row and is not bound to any table. So if you create a new row:

INSERT INTO table VALUES('a', 'b', 'c');

它将返回最后一个ID(无论新主键的值)。

It will return the last id (whatever value the new primary key has).

SELECT LAST_INSERT_ID();
=> 123 

有关详情,请参阅 手动

For details, please take a look at the manual:


LAST_INSERT_ID()(无参数)返回一个BIGINT(64位)值,表示由最近执行的INSERT语句为AUTO_INCREMENT列设置的第一个自动生成的值影响这样的列。例如,在插入一个生成AUTO_INCREMENT值的行之后,您可以获得如下值:
LAST_INSERT_ID() (with no argument) returns a BIGINT (64-bit) value representing the first automatically generated value that was set for an AUTO_INCREMENT column by the most recently executed INSERT statement to affect such a column. For example, after inserting a row that generates an AUTO_INCREMENT value, you can get the value like this:

如果您只想获取最后一个ID表,你可以这样做:

If you just want to get last ID in a table, you can do it like this:

SELECT id FROM table ORDER BY id DESC LIMIT 1;

这篇关于LAST_INSERT_ID()返回多行0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆