Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL : complex query dynamic select?
    primarykey
    data
    text
    <p>I searching for many times now on a complex MySQL query.</p> <p>It's an achievement system.</p> <p>Structure of tables is simple and form is symmetric.</p> <p>The first table (achievements_base) contains the achievements reference : each achievement have : - an ID (id of the row, auto-increment &amp; unique), - a code_id (reference of the achievement), - a rank_id (sub-category of achievement's code_id), - and the achievement name (display purposes).</p> <p>The second table (achievements_user) contains the achievements obtained by the users : each achievement unlocked have : - an ID (if of the row, auto-increment &amp; unique), - the code_id (reference of the achievement), - a rank_id (sub-category of achievement's code_id), - and the user id.</p> <p>The tables syntax is :</p> <pre><code>achievements_base id - code_id - rank_id - name 1 - 1 - 1 - foo 2 - 1 - 2 - bar 3 - 1 - 3 - foobar 4 - 1 - 4 - foofoo 5 - 2 - 1 - barbar achievements_user id - code_id - rank_id - user_id 1 - 1 - 1 - 1 2 - 1 - 2 - 1 3 - 2 - 1 - 1 </code></pre> <p>I want to display achievements that user don't have (GROUP BY code_id)</p> <pre><code>In the table exemple above, for example, expected result is, for the user_id 1 : 3 - 1 - 3 - foobar </code></pre> <p>But I don't see how to do that ! I've already tried multiples queries.</p> <p>Sorry for my English, I'm French !</p> <p>Thanks !</p> <p>edit, example of one of queries that I've tried :</p> <pre><code>SELECT AB.name FROM achievements_base AB RIGHT JOIN achievements_users AU ON AU.code_id = AB.code_id AND AU.rank_id = AB.rank_id WHERE (SELECT COUNT(*) FROM achievements_users AU WHERE AU.user_id = 1) = 0 GROUP BY AB.code_id ORDER BY AB.code_id ASC </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload