结合并简化SELECT和UPDATE SQL查询 [英] Combine and simplify SELECT and UPDATE sql query

查看:75
本文介绍了结合并简化SELECT和UPDATE SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

foreach (BidList t in bidList)
{
    query = "SELECT operator_id, plot_id, status FROM booking " +
        "WHERE status='open' AND postcode='" + _plot + "' AND operator_id='0'" +
        "ORDER BY datetime ASC;" +
        "UPDATE booking SET operator_id='" + t.OperatorId + "', status='allocated' " +
        "WHERE (plot_id=" + t.PlotId + " AND operator_id='0' AND status='open') LIMIT 1;";
    dbObject.InsertBooking(query);
}

我正在清理我的代码,并遇到了上述SQL查询.在使用SQL参数之前,我想问一下是否可以将它们组合在一起,如果可以,如何组合?

I am cleaning up my code, and came across the above SQL query. Before I make use of SQL parameters, I wanted to ask if it is possible to combine them, and if so, how?

推荐答案

不确定为什么需要使用限制.如果不需要保留更改项的记录,则可以消除查询中的选择"部分.

Not sure why you need to use Limit.  If you don't need to keep a record of the changed items, you can eliminate the Select portion on the query.

query = "UPDATE booking SET status='allocated' " +
        "WHERE (status='open' AND postcode='" + _plot + "' AND operator_id='0');";



这篇关于结合并简化SELECT和UPDATE SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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