tags:

views:

21

answers:

2
CREATE VIEW myView AS  SELECT *
FROM `ce_userbadges`
WHERE ceub_userid =85;

SELECT *
FROM ce_badge
LEFT JOIN myView ON ceb_id = ceub_badgeid;

So it has to select all badges user 85 has and also the badges they dont have (hence the left join).

I tryed this but it does the userid filtering after the join

SELECT *  FROM ce_userbadges
right join ce_badge on ceub_badgeid = ceb_id
WHERE ceub_userid = 85
+4  A: 
SELECT *  FROM ce_badge
LEFT JOIN ce_userbadges
ON ceub_badgeid = ceb_id AND ceub_userid = 85
Wrikken
+1  A: 

You can simply put the code of the view where you use it:

SELECT *
FROM ce_badge
LEFT JOIN (
  SELECT *
  FROM `ce_userbadges`
  WHERE ceub_userid = 85
) x ON ceb_id = ceub_badgeid;
Guffa
Thanks for the answer, this is a good alternative solution
nullptr