Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OUTPUT Clause in MySQL

Tags:

Is there a way to simulate the OUTPUT clause in MySQL, as we have a OUTPUT clause in SQL Server.

Here is the kind of query I have

UPDATE       employee SET          empage = 10 OUTPUT       INSERTED.empid WHERE        (empage < 10) 

As I need to have this functionality for MySQL server database too.

Kindly suggest the best way to achieve this functionality.

like image 463
Saravanan Avatar asked Apr 28 '11 10:04

Saravanan


People also ask

What is output clause in SQL?

The OUTPUT clause returns columns from the table being deleted ( deleted. ProductID , deleted. ProductPhotoID ) and columns from the Product table. This table is used in the FROM clause to specify the rows to delete. SQL Copy.

What is output in MySQL?

MySQL Shell can print results in table, tabbed, or vertical format, or as pretty or raw JSON output. From MySQL Shell 8.0. 14, the MySQL Shell configuration option resultFormat can be used to specify any of these output formats as a persistent default for all sessions, or just for the current session.

WHERE is output in MySQL?

7 Output Panel. The Output is located at the bottom of MySQL Workbench. Its select box includes the Action Output , History Output , and Text Output options.

How can I see output in SQL?

On the View menu, click Other Windows, and then click Output.


1 Answers

  1. You could create a trigger and insert values you need into another table.
  2. I'm not sure, but - for MYISAM tables you could lock employee table, select and insert values into another table, and then update and unlock employee table.

EDIT:

I have tried one scenario with InnoDb table, seems it works -

START TRANSACTION;  SELECT * FROM table WHERE id = 1 FOR UPDATE; -- lock rows -- Or call this select to insert and lock rows -- INSERT INTO table_output SELECT * FROM table WHERE id = 1 FOR UPDATE;  -- Make modifications UPDATE table SET column1 = '111' WHERE id = 1;  COMMIT; 

SELECT statement (FOR UPDATE clause)

like image 148
Devart Avatar answered Sep 19 '22 06:09

Devart