You can do this as a UNION statement or the long way. This is a UNION
example:

select rac.name as race, ch.*
from characters as ch
inner join races as rac
      on rac.raceID = ch.raceID
inner join entityLocation el
      on el.entityID = ch.characterID
      and el.visibility <=60
      and el.entityType =1
      AND el.containerType =6
      AND el.containerID =75402
where ch.handle<>'Khan'
UNION
select rac.name as race, npc.*
from npc as npc
inner join races as rac
      on rac.raceID = npc.raceID
inner join entityLocation el
      on el.entityID = npc.characterID
      and el.visibility <=60
      and el.entityType=10
      AND el.containerType =6
      AND el.containerID =75402

The long way is to do an individual IF( , , ) for each and every column you
need to return and not use the * notation.

One other problem with your IF statement was that you aliased *ALL* of
those columns being returned as 'charData'. That's not good under any
circumstance and would have failed you even if the * format were
acceptable.

Your,
Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine


                                                                                       
                                   
                      "Keith"                                                          
                                   
                      <[EMAIL PROTECTED]        To:       <[EMAIL PROTECTED]>          
                                
                      om>                      cc:                                     
                                   
                                               Fax to:                                 
                                   
                      06/11/2004 01:56         Subject:  Using IF                      
                                   
                      AM                                                               
                                   
                                                                                       
                                   
                                                                                       
                                   




g'day,

Am having a bit of a problem with using IF. This is the error message I
get:

-----
SELECT rac.name AS race,
IF (

el.entityType =1, ch. * , npc. *
)charData
FROM characters AS ch, entityLocation AS el, races AS rac, npc AS npc
WHERE el.entityType
IN ( 1, 10 ) AND el.containerType =6 AND el.containerID =75402 AND
IF (
el.entityType =1, el.entityID = ch.characterID AND el.visibility <=60 AND
ch.raceID = rac.raceID AND ch.handle <> 'Khan', el.entityID = npc.npcID AND
el.visibility <=60 AND npc.raceID = rac.raceID
)
LIMIT 0 , 30

MySQL said:


#1064 - You have an error in your SQL syntax.  Check the manual that
corresponds to your MySQL server version for the right syntax to use near
'*, npc. *  )charData
FROM characters AS ch, entityLocation AS
-----

What I want to do is select everything from characters if the el.entityType
is 1, else I want to select everything from npc table.



Cheers,
Keith






-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to