Mysql Lookup Q

I've got two Mysql tables:

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

And my main table, has lots of values.
First,Last,Middle,Address,LOOKUP_ID
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?
ecuguruAsked:
Who is Participating?
 
Aleksandar BradarićSoftware DeveloperCommented:
Try this:
---
SELECT
  t1.First,
  t1.Last,
  t1.Middle,
  t1.Address,
  t1.Lookup_ID,
  t2.Value
FROM
  yourTable t1
  LEFT JOIN Lookup t2 ON t2.ID = t1.Lookup_ID
WHERE
  t1.First = 'bob' AND
  t2.Value = 'Zero'
---
0
 
Aleksandar BradarićSoftware DeveloperCommented:
> What if they search for "blahblah" that doesn't exist in my lookup table?

Nothing will be returned (empty result set).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.