View Single Post
  #4  
Old 02-06-2013, 06:59 PM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

yeah, it's called a subquery.

say for instance you have a table called known_pets that has a column, called npc_type_id. this would obviously store the id for npc types that you know are pets.

if you wanted to double the hitpoints for all pets, you'd use the following query:

Code:
UPDATE
    npc_types
SET
    hp = hp * 2
WHERE
    npc_types.id
IN
    (SELECT npc_type_id FROM known_pets)
if you wanted to do something to everything that isn't a pet, you'd just use NOT IN, instead of IN.

be aware that subqueries can only return a single column from a table. more info can be found here: http://dev.mysql.com/doc/refman/5.0/en/subqueries.html
__________________
I muck about @ The Forge.
say(rand 99>49?'try '.('0x'.join '',map{unpack 'H*',chr rand 256}1..2):'incoherent nonsense')while our $Noport=1;
Reply With Quote