|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|