gpt4 book ai didi

sql - SQL中如何选择表的最后一条记录?

转载 作者:行者123 更新时间:2023-12-01 16:51:47 28 4
gpt4 key购买 nike

这是从表中选择所有记录的示例代码。有人可以告诉我如何选择该表的最后一条记录吗?

select * from table

当我使用:SELECT * FROM TABLE ORDER BY ID DESC LIMIT我收到此错误:第 1 行:“LIMIT”附近的语法不正确。这是我使用的代码:

private void LastRecord()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HELPDESK_OUTLOOKConnectionString3"].ToString());

conn.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("SELECT * FROM HD_AANVRAGEN ORDER BY " +
"aanvraag_id DESC LIMIT 1", conn);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
TextBox1.Text = (myReader["aanvraag_id"].ToString());
TextBox1.Text += (myReader["wijziging_nummer"].ToString());
TextBox1.Text += (myReader["melding_id"].ToString());
TextBox1.Text += (myReader["aanvraag_titel"].ToString());
TextBox1.Text += (myReader["aanvraag_omschrijving"].ToString());
TextBox1.Text += (myReader["doorlooptijd_id"].ToString());
TextBox1.Text += (myReader["rapporteren"].ToString());
TextBox1.Text += (myReader["werknemer_id"].ToString());
TextBox1.Text += (myReader["outlook_id"].ToString());
}
}

最佳答案

没有任何进一步的信息,我们能做的最好的数据库等就是这样

SQL Server

SELECT TOP 1 * FROM Table ORDER BY ID DESC

MySql

SELECT * FROM Table ORDER BY ID DESC LIMIT 1

关于sql - SQL中如何选择表的最后一条记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5191503/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com