MySQL : Assign Query Results to User Defined Variables for Reuse - DevDummy

Latest

Coding Hacks, Shared ...

Tuesday, July 31, 2018

MySQL : Assign Query Results to User Defined Variables for Reuse




In SQL Scripting, it is often required to reuse the queried values, while executing queries in sequence.

User defined variables are a good methodology to deal with above situation.

SELECT @publisher_id := @id from publisher where publisher_name = 'O'Reilly Media, Inc.' ;

INSERT IGNORE INTO 
book (isbn, author, name, category, year, publisher_id)
VALUES
(9780596009205, 'Kathy Sierra, Bert Bates', 'Head First Java', 'Technology', 2013, @publisher_id );

https://www.devdummy.com/2018/06/mysql-execute-queries-with-variables.html


No comments:

Post a Comment