2017-07-12 4 views
1

Folgende ist meine Abfrage: Update auf einer anderen Spalte ist

select c.*,u.fullname,u.userphoto from chat_messages 
    c left join us_signup u on u.id=c.fromid 
    where c.fromid in(?,?) and c.toid in(?,?) and c.jobid=? 
    order by c.received_date asc 

eine Spalte in der chat_messages Tabelle „readi“ genannt, die ich

aktualisieren möchten

ich habe bereits refered:

How to UPDATE and SELECT at the same time in MySQL

Is there a way to SELECT and UPDATE rows at the same time?

etc .. aber konnte meine Abfrage nicht ändern ..

+0

https://stackoverflow.com/questions/24691576/mysql-update-column-then-select-updated- Wert - obwohl ich mich frage, ob nicht ein historisches Protokoll gewünscht wird oder etwas (einfügen und get generierten Schlüssel). –

Antwort

1

Die Antworten, die Sie verknüpft sind, sind beide für MS SQL Server (In der MySQL-Tagged Frage lesen Sie die Kommentare). In MySQL gibt es keine OUTPUT-Klausel oder was auch immer. Die einzige Möglichkeit, die ich mir vorstellen kann, ist die Verwendung von user-defined variables.

Für eine einzelne Zeile:

SET @v := NULL; 
UPDATE your_table 
SET column_name = 'whatever' 
WHERE another_column = 'foo' 
AND @v := column_you_want_to_store 
LIMIT 1; 
SELECT @v; 

für mehrere Zeilen:

SET @v := ''; 
UPDATE your_table 
SET column_name = 'whatever' 
WHERE another_column = 'foo' 
AND @v := (SELECT CONCAT_WS(', ', column_you_want_to_store, @v)); 
SELECT @v; 
Verwandte Themen