Update and select in one query
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 = "UPDATE tblPopUp 
                 SET PopUp = 'False' 
               WHERE DisplayNo = 1"
开发者_JS百科
...and:
string sql1 = "SELECT Period  
                 FROM tblPopUp 
                WHERE DisplayNo = 1"
How can I combine them?
UPDATE tblPopUp  
SET PopUp = 'False', Period = Period  
OUTPUT DELETED.Period
WHERE DisplayNo = 1
For more information about OUTPUT clause please check this post.
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.
The correct way to do this (now for MySQL 5+), would be with a stored procedure.
Try This
UPDATE tblPopUp 
             SET PopUp = 'False' 
           WHERE DisplayNo = '1'
(
SELECT Period  
             FROM tblPopUp 
            WHERE DisplayNo = '1'
)
Old Q, but still in usage, for psql solution, try this:
UPDATE table SET column = value
WHERE condition
RETURNING column;
 加载中,请稍侯......
      
精彩评论