PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > with DISTINCT keyword
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
with DISTINCT keyword

Réponse
 
LinkBack Outils de la discussion
Vieux 10/02/2008, 15h18   #1
Ciaran
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut with DISTINCT keyword

Hi,
I'm trying to select only unique values from 3 columns
(filter1,filter2,filter3) and return them in their original columns.
I've got this so far but the UNION simply lists all results under the
filter1 column. How can I correct this please?

SELECT DISTINCT filter1 AS filter1
FROM `home_index`
UNION
SELECT DISTINCT filter2 AS filter2
FROM `home_index`
UNION
SELECT DISTINCT filter3 AS filter3
FROM `home_index`

Thanks for any !
Ciarán
  Réponse avec citation
Vieux 10/02/2008, 15h41   #2
PleegWat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with DISTINCT keyword

On Sun, 10 Feb 2008 06:18:44 -0800, Ciaran wrote:

> Hi,
> I'm trying to select only unique values from 3 columns
> (filter1,filter2,filter3) and return them in their original columns.
> I've got this so far but the UNION simply lists all results under the
> filter1 column. How can I correct this please?
>
> SELECT DISTINCT filter1 AS filter1
> FROM `home_index`
> UNION
> SELECT DISTINCT filter2 AS filter2
> FROM `home_index`
> UNION
> SELECT DISTINCT filter3 AS filter3
> FROM `home_index`
>
> Thanks for any !
> Ciarán


Are you looking for this?

SELECT DISTINCT filter1 AS filter1, '' AS filter2, '' AS filter3
FROM home_index
UNION
SELECT DISTINCT '' AS filter1, filter2 AS filter2, '' AS filter3
FROM home_index
UNION
SELECT DISTINCT '' AS filter1, '' AS filter2, filter3 AS filter3
FROM home_index

--
PleegWat
Remove caps to reply
  Réponse avec citation
Vieux 10/02/2008, 16h06   #3
Ciaran
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with DISTINCT keyword

On Feb 10, 2:41 pm, PleegWat
<pleegwat.REM...@CAPS.leegwater-68.nl.INVALID> wrote:
> On Sun, 10 Feb 2008 06:18:44 -0800, Ciaran wrote:
> > Hi,
> > I'm trying to select only unique values from 3 columns
> > (filter1,filter2,filter3) and return them in their original columns.
> > I've got this so far but the UNION simply lists all results under the
> > filter1 column. How can I correct this please?

>
> > SELECT DISTINCT filter1 AS filter1
> > FROM `home_index`
> > UNION
> > SELECT DISTINCT filter2 AS filter2
> > FROM `home_index`
> > UNION
> > SELECT DISTINCT filter3 AS filter3
> > FROM `home_index`

>
> > Thanks for any !
> > Ciarán

>
> Are you looking for this?
>
> SELECT DISTINCT filter1 AS filter1, '' AS filter2, '' AS filter3
> FROM home_index
> UNION
> SELECT DISTINCT '' AS filter1, filter2 AS filter2, '' AS filter3
> FROM home_index
> UNION
> SELECT DISTINCT '' AS filter1, '' AS filter2, filter3 AS filter3
> FROM home_index
>
> --
> PleegWat
> Remove caps to reply



Yes, Thanks PleegWat - That will do nicely. It produces empty fields
but I can just filter them out with php.
Thanks for the !
Ciarán
  Réponse avec citation
Vieux 11/02/2008, 00h16   #4
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with DISTINCT keyword

PleegWat wrote:
> On Sun, 10 Feb 2008 06:18:44 -0800, Ciaran wrote:
>
>> Hi,
>> I'm trying to select only unique values from 3 columns
>> (filter1,filter2,filter3) and return them in their original columns.
>> I've got this so far but the UNION simply lists all results under the
>> filter1 column. How can I correct this please?
>>
>> SELECT DISTINCT filter1 AS filter1
>> FROM `home_index`
>> UNION
>> SELECT DISTINCT filter2 AS filter2
>> FROM `home_index`
>> UNION
>> SELECT DISTINCT filter3 AS filter3
>> FROM `home_index`
>>
>> Thanks for any !
>> Ciarán

>
> Are you looking for this?
>
> SELECT DISTINCT filter1 AS filter1, '' AS filter2, '' AS filter3
> FROM home_index
> UNION
> SELECT DISTINCT '' AS filter1, filter2 AS filter2, '' AS filter3
> FROM home_index
> UNION
> SELECT DISTINCT '' AS filter1, '' AS filter2, filter3 AS filter3
> FROM home_index


A "UNION" implies DISTINCT, so the DISTINCTs should not be required.


  Réponse avec citation
Vieux 11/02/2008, 17h36   #5
PleegWat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with DISTINCT keyword

On Sun, 10 Feb 2008 07:06:40 -0800, Ciaran wrote:

> On Feb 10, 2:41 pm, PleegWat
> <pleegwat.REM...@CAPS.leegwater-68.nl.INVALID> wrote:
>> On Sun, 10 Feb 2008 06:18:44 -0800, Ciaran wrote:
>> > Hi,
>> > I'm trying to select only unique values from 3 columns
>> > (filter1,filter2,filter3) and return them in their original columns.
>> > I've got this so far but the UNION simply lists all results under the
>> > filter1 column. How can I correct this please?

>>
>> > SELECT DISTINCT filter1 AS filter1
>> > FROM `home_index`
>> > UNION
>> > SELECT DISTINCT filter2 AS filter2
>> > FROM `home_index`
>> > UNION
>> > SELECT DISTINCT filter3 AS filter3
>> > FROM `home_index`

>>
>> > Thanks for any !
>> > Ciarán

>>
>> Are you looking for this?
>>
>> SELECT DISTINCT filter1 AS filter1, '' AS filter2, '' AS filter3 FROM
>> home_index
>> UNION
>> SELECT DISTINCT '' AS filter1, filter2 AS filter2, '' AS filter3 FROM
>> home_index
>> UNION
>> SELECT DISTINCT '' AS filter1, '' AS filter2, filter3 AS filter3 FROM
>> home_index
>>
>> --
>> PleegWat
>> Remove caps to reply

>
>
> Yes, Thanks PleegWat - That will do nicely. It produces empty fields but
> I can just filter them out with php. Thanks for the !
> Ciarán


The field names will be the same for all rows. That's how it's designed
and there's no getting around that. If you prefer, you can use NULL
instead of '', but that won't matter much for the php side.

--
PleegWat
Remove caps to reply
  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 01h31.


É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,10476 seconds with 13 queries