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 > How to include some empty answers in a query?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to include some empty answers in a query?

Réponse
 
LinkBack Outils de la discussion
Vieux 12/10/2007, 13h20   #1
K.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to include some empty answers in a query?

Hi, maybe the subject of this message is not very good. Here is my
problem. Considering a single table, we have a look at two columns. Both
are ID's like that: "post with ID = x belongs to category with ID = y".
I want to perform the following request:
All posts belonging to category 12 are needed; if in this very same
table the same post also belongs to another category, get the ID of that
other category; if the post doesn't belong to any other category, get 0
instead.
For instance, if post with ID 115 belongs to category 12 only,
return (115,0); if on the other hand it belongs to category 12 and 13,
return (115,13).

Thank you by advance, regards, K.
  Réponse avec citation
Vieux 12/10/2007, 13h29   #2
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to include some empty answers in a query?

On 12 Oct, 12:20, "K." <k...@somewhere.org> wrote:
> Hi, maybe the subject of this message is not very good. Here is my
> problem. Considering a single table, we have a look at two columns. Both
> are ID's like that: "post with ID = x belongs to category with ID = y".
> I want to perform the following request:
> All posts belonging to category 12 are needed; if in this very same
> table the same post also belongs to another category, get the ID of that
> other category; if the post doesn't belong to any other category, get 0
> instead.
> For instance, if post with ID 115 belongs to category 12 only,
> return (115,0); if on the other hand it belongs to category 12 and 13,
> return (115,13).
>
> Thank you by advance, regards, K.


Suppose it belogs to 12, 13 and 14?

  Réponse avec citation
Vieux 12/10/2007, 15h51   #3
K.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to include some empty answers in a query?

Le Fri, 12 Oct 2007 11:29:05 +0000, Captain Paralytic a écrit:
> Suppose it belogs to 12, 13 and 14?

Sorry for that ; it can't happen in my database (according to what it
really means). But just take any of 13 or 14; it will be OK.
  Réponse avec citation
Vieux 12/10/2007, 17h14   #4
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to include some empty answers in a query?

On 12 Oct, 14:51, "K." <k...@somewhere.org> wrote:
> Le Fri, 12 Oct 2007 11:29:05 +0000, Captain Paralytic a écrit:> Supposeit belogs to 12, 13 and 14?
>
> Sorry for that ; it can't happen in my database (according to what it
> really means). But just take any of 13 or 14; it will be OK.


So we'd be looking at something like:

SELECT
CONCAT(
'('
t1.post,
',' ,
IFNULL(t2.category,0),
')'
) `return`
FROM table t1
LEFT JOIN table t2 ON t1.post = t2.post AND t1.category <> t2.category
WHERE t1.category = 12

  Réponse avec citation
Vieux 12/10/2007, 19h24   #5
K.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to include some empty answers in a query?

Le Fri, 12 Oct 2007 15:14:29 +0000, Captain Paralytic a écrit:
> So we'd be looking at something like:


Thank you for everything; I will have a look at that tonight.
Regards, K.
  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 01h01.


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