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

Beitrag lesen

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