Lookup Tables Empty?

Hi there,

I’m working my way through Build Your Own Database Driven Website (3rd Edition) and although it’s been excellent thus far, I’ve hit a snag.

I’m at Chapter 5: Relational Database Design, near the end of the chapter, and I’ve just established a lookup table called JOKECATEGORY which is drawing information from JOKE and CATEGORY tables.

When I try to SELECT information from JOKECATEGORY it just gives me an EMPTY SET message. Is this normal? I haven’t inserted any information to JOKECATEGORY, because I was under the impression it was taking its information from those other tables I mentioned. Am I wrong? Should I be inputting information? Perhaps I’ve misinterpreted somewhere.

Any help is greatly appreciated!

No they should not be empty. There should be data which ties the two together.

Example:

In Jokes (format is JokeID, Joke, Punchline)
1, Why Did the Chicken Cross the Road, To Get to the Other Side
2, What is a cows favorite subject in school?, Moo-sic!
3, Where do sheep get their coats cut? At the baa-bershop!

In Category (format is CategoryID, Category
1, Classic Jokes
2, Classic Puns

In your JokeCategory Table, you’d have something like (format CategoryID, JokeID)
1, 1
2, 2
2, 3

I think you missed a step somewhere when you created your table - you forgot to populate them.

Hmm, perhaps the question I was asking was too bloated. Would anyone be able to tell me this then: is a lookup table meant to be empty?

Thanks for the reply. I’ve managed to add the appropriate values to JOKECATEGORY, but I’m still receiving an “empty set” message. This is beginning to get frustrating :frowning:

Here is the MYSQL code I’m trying to execute, if it’s of any use

mysql> SELECT joketext 
    -> FROM joke INNER JOIN jokecategory 
    ->   ON joke.id = jokeid 
    -> INNER JOIN category 
    ->   ON categoryid = category.id 
    -> WHERE name = "Knock-knock"; 

SCRATCH THAT! I dialed back the code a bit, and executed it section by section, and found that the WHERE=“Knock-knock” statement was the culprit. I change that to search for another thing, and it worked :slight_smile:

Thanks very much for the help