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 > Where clause - knowing what part results matched on - possible?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Where clause - knowing what part results matched on - possible?

Réponse
 
LinkBack Outils de la discussion
Vieux 16/04/2006, 11h09   #1
David Smithz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Where clause - knowing what part results matched on - possible?

Hi,

If you run a query which has a WHERE statement in which has a few
possibilities separated OR statements, e.g.

Select * from table where (Afield = 2) OR (Bfield = 2) OR (Cfield = 2)

In the returned results is it possible to know what particular part of the
WHERE clause a field matched.

For example, if the above query returned 6 rows, I would want to be able to
tell know if the first result matched on Afield and Cfield but not Bfield.
Then see that row 2 matched on Bfield only etc.

Is this possible?

Thanks in advance.

David



  Réponse avec citation
Vieux 16/04/2006, 16h13   #2
Gordon Burditt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Where clause - knowing what part results matched on - possible?

>If you run a query which has a WHERE statement in which has a few
>possibilities separated OR statements, e.g.
>
>Select * from table where (Afield = 2) OR (Bfield = 2) OR (Cfield = 2)
>
>In the returned results is it possible to know what particular part of the
>WHERE clause a field matched.


Yes. Look at the results returned and evaluate the conditions of
the WHERE clause in a programming language.

>For example, if the above query returned 6 rows, I would want to be able to
>tell know if the first result matched on Afield and Cfield but not Bfield.
>Then see that row 2 matched on Bfield only etc.


You can also select additional data to be returned with the record
using an arbitrary expression, like:

if(afield = 2, 1, 0) as matchedona,
if(bfield = 2, 1, 0) as matchedonb,
if(cfield = 2, 1, 0) as matchedonc

Gordon L. Burditt
  Réponse avec citation
Vieux 17/04/2006, 18h52   #3
onedbguru@firstdbasource.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Where clause - knowing what part results matched on - possible?


Now for the ANSI standard version of the query.

select Afield,Bfield,Cfield, -- get the values of these fields
case when Afield=2 then 1 else 0 end as matchedonA,
case when Bfield=2 then 1 else 0 end as matchedonB,
case when Cfield=2 then 1 else 0 end as matchedonC,
other,
fields
from .....
where.....

1 and 0 can be 'A' and NULL or 'A' and 'Z' or. or or.....

It is a bit more wordy, but will work on MySQL, Oracle RDBMS(8,9,10),
Oracle Rdb, DB2, Informix, Sybase, and yes, even SQLServer (I think???)

  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 23h00.


É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,07618 seconds with 11 queries