Update and select in one query

前端 未结 5 2026
臣服心动
臣服心动 2020-12-06 05:38

I found similar questions with correct answers. But they\'re a bit complicated for me. I just want a simple basic statement.

I have:

string sql = \"         


        
相关标签:
5条回答
  • 2020-12-06 06:06
    UPDATE tblPopUp  
    SET PopUp = 'False', Period = Period  
    OUTPUT DELETED.Period
    WHERE DisplayNo = 1
    

    For more information about OUTPUT clause please check this post.

    0 讨论(0)
  • 2020-12-06 06:08

    Try This

    UPDATE tblPopUp 
                 SET PopUp = 'False' 
               WHERE DisplayNo = '1'
    (
    SELECT Period  
                 FROM tblPopUp 
                WHERE DisplayNo = '1'
    )
    
    0 讨论(0)
  • 2020-12-06 06:10

    You can't.

    There's no convention in a SQL UPDATE statement for returning data. And vice versa -- a SELECT statement doesn't write information to a table.

    If you've found questions/answers that you feel are similar to what you want, please provide links.

    0 讨论(0)
  • 2020-12-06 06:19

    Old Q, but still in usage, for psql solution, try this:

    UPDATE table SET column = value
    WHERE condition
    RETURNING column;
    
    0 讨论(0)
  • 2020-12-06 06:24

    The correct way to do this (now for MySQL 5+), would be with a stored procedure.

    0 讨论(0)
提交回复
热议问题