Set - How To Select From MySQL Where Table Name Is Variable - Stack Overflow
Set - How To Select From MySQL Where Table Name Is Variable - Stack Overflow
Home
PUBLIC
Stack Overflow
Tags
How to select from MySQL where Table name is Variable Ask Question
Users
Jobs I have a case where getting the table name should be from a set variable like: asked 6 years, 10 months ago
but doing that way MySQL outputs an error, so could someone show me how I can achieve that,
Learn More
because these are my baby steps in MySQL. Looking for a job?
10
mysql set tablename Software Engineer (Full-stack)
Generation Ciudad de México, Mexico
mysql reactjs
share improve this question edited Feb 28 at 18:19 asked Jan 10 '12 at 20:19
Jacob Alvarez Burimi
2,131 1 6 15 7,430 9 48 86 Full Stack Engineer- Ruby on Rails
Elastic No office location
add a comment
REMOTE
elasticsearch reactjs
1 Answer active oldest votes
You'd have to do this with a prepared statement. Something like: Full-Stack Developer, WordPress
Sanborn No office location
SET @s = CONCAT('select * from ', @Cat, ' where ID = ', @ID_1); $60K - $90K REMOTE
68
php nodejs
PREPARE stmt1 FROM @s;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
Linked
share improve this answer answered Jan 10 '12 at 20:25
0 how to use a value from sql result as table
Joe Stefanelli name for its sub query?
109k 13 189 203
How to select a table in query as variable in
0
Join Stack Overflow to learn, shareBy
knowledge, andyou
using our site, build
acknowledge that you have read and understand our Email
your career. CookieSign UpPrivacy Policy,
Policy, OR SIGNand
IN WITH Google
mysql?
our Terms of Service. Facebook
One more thing it show resul only when i remove DEALLOCATE PREPARE stm1; – Burimi Jan 10 '12 at
20:37 0 MySQL: Count rows of a table that is
named in the current table
Brilliant solution. Helped me to solve the issue I'm having, thanks. – Tim Visée May 26 '16 at 12:36
1 In MySQL trigger, is it possible to set a
What does the DEALLOCATE PREPARE do? – Frozen Flame Jun 29 '16 at 2:59
user variable with NEW.col and use that in
update query?
1 @FrozenFlame, release the stmt1 . If you do not release it, may you encounter the max limit of statements,
enforced by max_prepared_stmt_count variable system, how you can read here. – ruzenhack Jul 12 '17 at -2 Declaring variables in SQL and “Must
19:29 declare the table variable @TBL” error
is this still valid syntax in 2018?? – Anthony Jul 17 at 1:51 0 Select from table with IF
Related
Sign up or log in Post as a guest 124 How do I add more members to my ENUM-
type column in MySQL?
required, but never shown 674 How to get the sizes of the tables of a
MySQL database?
Sign up using Email and Password
949 Reference - What does this error mean in
PHP?
Post Your Answer 1404 How to import an SQL file using the
command line in MySQL?
By click ing "Post Your Answer", you ack nowledge that you have read our updated terms of service, privacy policy and cook ie
policy, and that your continued use of the website is subject to these policies. Hot Network Questions
Possible definitions of exponential function
Not the answer you're looking for? Browse other questions tagged mysql set tablename or ask your Why do the British use the word "flipping" for
emphasis?
own question.
Alternating items in a collection
question feed
STACK OVERFLOW PRODUCTS COMPANY STACK EXCHANGE Blog Facebook Tw itter LinkedIn
NETWORK
Questions Teams About
Technology
Jobs Talent Press
Life / Arts
Developer Jobs Directory Engagement Work Here
Culture / Recreation
Salary Calculator Enterprise Legal
Science
Help Privacy Policy
Other
Mobile Contact Us site design / logo © 2018 Stack Exchange Inc; user contributions
licensed under cc by-sa 3.0 w ith attribution required.
Disable Responsiveness rev 2018.11.7.32103