wichtig: IF das ungleich das DANN JOIN, sonst weise wert zu - möglich?

Hallo.

SELECT fid, user, themainfile, used, whatisit, whoused, whogive  
  
FROM thefiles  
  
JOIN profile ON profile.id=thefiles.whoused  
  
WHERE  
whatisit='".intval($shopsid)."' AND tid='".intval($_SESSION['teamid'])."' 

So der JOIN soll nur stattfinden wenn thefiles.whoused!='9999'. Falls thefiles.whoused='9999', dann soll user='niemand' sein.

Ist das irgendwie möglich?
Versuch war:

IF(thefiles.whoused!='9999',(JOIN profile ON profile.id=thefiles.whoused),(user='niemand') )

aber das klappt irgendwie nicht :(

Helft mir.

Gruss,

Wichtig

  1. yo,

    Ist das irgendwie möglich?

    gibt verschiedene möglichkeiten in abhängigkeiten, was du willst. zum einen könntest du das IF oder eine CASE anweisung in die Projektion einbauen, sprich dort, woe die spalten ausgegeben werden.

    SELECT fid,
           CASE
               WHEN whoused = '9999' THEN 'niemand'
               ELSE user
           END,
           themainfile,
           used,
           whatisit,
           whoused,
           whogive
    FROM thefiles
    JOIN profile ON profile.id=thefiles.whoused
    WHERE whatisit='".intval($shopsid)."' AND tid='".intval($_SESSION['teamid'])."'
    ;

    oder aber du benutzt UNION ALL
    SELECT fid,
           user,
           themainfile,
           used,
           whatisit,
           whoused,
           whogive
    FROM thefiles
    JOIN profile ON profile.id=thefiles.whoused
    WHERE whatisit='".intval($shopsid)."' AND tid='".intval($_SESSION['teamid'])."'
    AND whoused <> '9999'
    UNION ALL
    SELECT NULL,
           'niemand',
           NULL,
           NULL,
           NULL,
           NULL,
           NULL
    FROM thefiles
    JOIN profile ON profile.id=thefiles.whoused
    WHERE whatisit='".intval($shopsid)."' AND tid='".intval($_SESSION['teamid'])."'
    AND whoused = '9999'
    ;

    Ilja