• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

SQL Gone Mad?!?

nza

New member
This would seem to be an extremely simple query... However, the results I'm getting disagree and its driving me mad trying to figure out! Let's see if you can deduce the problem...

Code:
SELECT h.habitat_ID, h.habitat_name, m.monster_name, m.monster_habitat 
  FROM pkmn_habitat h, pkmn_monster m 
    WHERE h.habitat_ID = '8' 
      AND m.monster_habitat = h.habitat_ID
Originally this was part of a much larger query, when it became clear that equijoining monster_habitat = habitat_ID was failing (only where habitat_ID was 9), I reduced the size of the query and began asking for the IDs that I was using to join on.

At that point I saw that it was joining a monster_habitat of mn (1-9) to habitat_ID of hn+1 (2-9). If mn was 9, no habitat_ID would be matched and the larger query failed.

Here's a screen of the first query's results...
qmnuqhn1.png


Clearly, Kyogre's habitat_ID is 7 and yet its being joined to the habitat_ID of 8... Why in the hell is it doing this?

As frustrating as this is, it ups the ante when the following continues to work...

Initially the different script gets a value from the URI, let's say "urban" The name and ID are queried for, which returns Urban and 8. Later, I run a larger query, again reduced for this thread, which uses the ID query A got, again being 8.

So the query, call it B, getting data relevant to monsters with that ID, 8, is done...
Code:
SELECT monster_name, monster_habitat
  FROM pkmn_monster
    WHERE monster_habitat = '8'
And the result...
qmnuqhn2.png


...yea...
 
Back
Top Bottom