Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use the look-up value from another look up table?

Posted on 2011-09-05
1
Medium Priority
?
247 Views
Last Modified: 2012-08-14

I want to have a script in the procedure to quickly get the version number from the Version table below by inputing the value number, and execute corresponding module:

If version is "1.1" THEN run module 1
If Version is "1.2" THEN run module 2

Table Version:
Value  Version
1      1.1
2      2.0

Thanks a lot.
0
Comment
Question by:heyday2004
1 Comment
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 36488310
Hi.

First, if you have not created a procedure before, here is the reference:
http://dev.mysql.com/doc/refman/5.5/en/create-procedure.html

Then you can get version into a variable like so:

DECLARE version_variable VARCHAR(10);
SELECT `Version` 
INTO version_variable
FROM `Version`
WHERE `Value` = value_variable;

Open in new window


Using that variable, the structure of IF statement could look like this:
IF (condition 1) THEN
   -- do one thing
ELSEIF (condition 2)
   -- do something else
ELSE
   -- do something as default
END IF;

Open in new window


Let's see if you can put together what you need from that. You can post back if you have any difficulties, but this way you should get a better understanding.

Hope that helps.

Kevin
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question