PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > NOT IN alternative
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
NOT IN alternative

Réponse
 
LinkBack Outils de la discussion
Vieux 24/03/2006, 16h17   #1
chrisoftoday@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut NOT IN alternative

Firstly, I know there's a lot of old posts on this topic but none seem
to be relevant to my problem (selecting from a single table rather than
several different tables)...

I have a table with a user identifier (uID) and a movie identifier
(movID) and need to select the movie identifiers that appear in the
table for uID-1 but not for uID-2, using an alternative to NOT IN as it
isn't supported by the version of MySQL that I'm using.

I'd be grateful if anyone could .

  Réponse avec citation
Vieux 24/03/2006, 17h40   #2
Bill Karwin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: NOT IN alternative

<chrisoftoday@googlemail.com> wrote in message
news:1143217047.078367.185300@i40g2000cwc.googlegr oups.com...
> I have a table with a user identifier (uID) and a movie identifier
> (movID) and need to select the movie identifiers that appear in the
> table for uID-1 but not for uID-2


You can use an outer join with a self-join to do this. The important part
is to put the uID=2 condition in the ON clause, not the WHERE clause.

SELECT m1.movID
FROM myMovieTable AS m1 LEFT OUTER JOIN myMovieTable AS m2
ON m1.movID = m2.movID AND m1.uID = 1 AND m2.uID = 2
WHERE m2.movID IS NULL

> using an alternative to NOT IN as it
> isn't supported by the version of MySQL that I'm using.


I know what you mean here, but for what it's worth, NOT IN actually is
supported by MySQL 4.0. You can do "NOT IN (1, 2, 3)". It's subqueries
that aren't supported until MySQL 4.1.

Regards,
Bill K.


  Réponse avec citation
Vieux 27/03/2006, 13h54   #3
chrisoftoday@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: NOT IN alternative

Ah. This was returning a movID for all the movies in the table but I
moved the "AND m1.uID=1" down into the where condition and it seems to
have done the trick.

Thanks for pointing me in the right direction

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h31.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09808 seconds with 11 queries