Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a site in which user can choose three programmes between 9. I would like to have a view that gives me the 6 programmes a user didn't choose. I've created programmes using taxonomy so each of my users have a term reference on programmes that contain the 3 programmes.

Any idea would be appreciated, Thanks

share|improve this question
Have you looked at the Views Raw SQL module? – Triskelion Feb 26 '13 at 21:36

Forget the Views Raw SQL module. Simple SQL is not going to give you the result you need. Queries look for what is there, not what isn't.

You will need to construct two lists. First, the list of programmes the user has selected.

$selected_programmes = array();

foreach ($user->field_taxonomy_programme['und'] as $selected_programme) {
  $selected_programmes[] = $selected_programme->name;


Second, the list of available programs.

$available_programmes = array();

$vocabulary = taxonomy_vocabulary_machine_name_load('programmes');

$programmes = taxonomy_get_tree($vocabulary->vid);

foreach($programmes as $programme) {

  $available_programmes[] = $programme->name;


Then you can use the two lists to produce a list of the unselected programmes, which can then be used to construct your query.

$unselected_programmes = array_diff( $available_programmes, $selected_programmes);

There is no way around it. The only way to construct a query for values which are not present is programmatically. I would suggest the use of a block with a php snippet to display this information.

share|improve this answer
I'm that isn't true- surely they can just use the NOT IN (SELECT...) subquery syntax? – cjm2671 Jul 8 '13 at 23:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.