本文介绍了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:

如果您只想获取最后一个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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 21:42
查看更多