Skip to content

Instantly share code, notes, and snippets.

@burubur
Created January 1, 2018 07:30
Show Gist options
  • Save burubur/685d29ceb8e3a16ccd0fcd5c88899954 to your computer and use it in GitHub Desktop.
Save burubur/685d29ceb8e3a16ccd0fcd5c88899954 to your computer and use it in GitHub Desktop.
#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