List:General Discussion« Previous MessageNext Message »
From:Johnny Withers Date:December 20 2010 5:59pm
Subject:Re: Problem with WHERE .. IN
View as plain text  
The sub-select only returns a single row, so IN(...) is only looking at a
single value in the list .. it doesn't "expand" to into IN (5,7,11).

On Mon, Dec 20, 2010 at 11:52 AM, muhammad subair <msubair@stripped> wrote:

> I have table post (id INT and parent VARCHAR)
>
> +------+-------------+
> | id   | parent      |
> +------+-------------+
> |    1 | 0           |
> |    2 | 0           |
> |    3 | 1           |
> |    4 | 0           |
> |    5 | 1           |
> |    6 | 0           |
> |    7 | 1,5         |
> |    8 | 1,5         |
> |    9 | 1,5         |
> |   10 | 5,7,11      |
> |   11 | 1,5,7,10    |
> |   12 | 1,5,7,10,11 |
> +------+-------------+
>
> SELECT id FROM post WHERE where id IN (SELECT parent FROM post WHERE id =
> 10);
> +------+
> | id   |
> +------+
> |    5 |
> +------+
>
> whereas the results I want is
>
> +------+
> | id   |
> +------+
> |    5 |
> |    7 |
> |   11 |
> +------+
>
> Please tell me, where is wrong
>
> Thanks & Regards
> --
> Muhammad Subair
> +62 8176583311
>



-- 
-----------------------------
Johnny Withers
601.209.4985
johnny@stripped

Thread
Problem with WHERE .. INmuhammad subair20 Dec
  • Re: Problem with WHERE .. INJohnny Withers20 Dec
    • Re: Problem with WHERE .. INDan Nelson20 Dec