Image

Imageelvishly wrote in Imagephp

multiple mysql selects in one query

Hi,

I have an issue with multiple selects within one query.

My problem is that I have something like this set up:

table: entries
+----------+------------+------------+
| genres   | categories | characters |
+----------+------------+------------+
| 1        | 1,2,3      |  1,5,29,13 |
+----------+------------+------------+

And then I have separate tables for genres/categories/characters with the IDs and names. Basically, the numbers in the entries table is the imploded array. The numbers match up with the actual IDs in the genre/category/character tables, and then (what I'm trying to attempt) it should output a list of the names.

I can get this working if I just use ONE of the three classifications (like characters) by using this:

SELECT characterName, characterID FROM characters WHERE characterID IN (1,5,29,13)

Which seems simple enough, I guess (the 1,5&c. is actually a variable with the actual numbers, but I changed it here to let it make more sense), but when I just use that code, then it displays at least 30 rows of the character's name. Not good. So I added in a LIMIT with the number of characters in there. That was okay.

I then tried to use the query to ALSO select the genres and categories (I'm trying to limit how many queries I use) but I ran into a problem:

The "LIMIT" numbers for each differs.

And so, my question is: how do I make it different?

Will I have to just stick it out and use separate queries? =/

I have entertained the idea I'm going about this the completely wrong way, but erm, I can't think of any other way to do it. ;_;