Created
January 1, 2018 07:30
-
-
Save burubur/685d29ceb8e3a16ccd0fcd5c88899954 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#MySQL 5.7.12 | |
#please drop objects you've created at the end of the script | |
#or check for their existance before creating | |
#'\\' is a delimiter | |
#select version() as 'mysql version'; | |
\\ | |
set @ids := '3,1'; | |
\\ | |
select @ids; | |
\\ | |
#create table samples (id int, name varchar(100)); | |
desc samples; | |
\\ | |
insert into samples values (1, 'a'); | |
\\ | |
insert into samples values (2, 'b'); | |
\\ | |
insert into samples values (3, 'c'); | |
\\ | |
#select * from samples; | |
\\ | |
#select * from samples where id in (3,1); | |
\\ | |
set @sql = concat("SELECT * FROM `samples` WHERE `samples`.Id in (" , @ids, ")"); | |
\\ | |
PREPARE stmt FROM @sql; | |
\\ | |
EXECUTE stmt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment