Mysql Lookup Q

Posted on 2007-07-24
Last Modified: 2010-04-01
I've got two Mysql tables:

Table: Lookup
ID | Value
0  | Zero
1  | One
2  | Two

And my main table, has lots of values.
Where lookup id is 1,2,3..

I'd like to be able to do a search like:
where first="bob" and lookup_id = "Zero"
Convert the lookup_id to its value, and search my main table for the lookup_id returned.

I'm pretty sure it's a standard lookup, but I don't know the syntax.  Also, I'm not sure how I trap if no results come back from the lookup?  What if they search for "blahblah" that doesn't exist in my lookup table?
Question by:ecuguru
    LVL 17

    Accepted Solution

    Try this:
      yourTable t1
      LEFT JOIN Lookup t2 ON t2.ID = t1.Lookup_ID
      t1.First = 'bob' AND
      t2.Value = 'Zero'
    LVL 17

    Expert Comment

    > What if they search for "blahblah" that doesn't exist in my lookup table?

    Nothing will be returned (empty result set).

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now