On Tue, Nov 17, 2009 at 7:17 AM, Ilya <[email protected]> wrote:

> I just developed some code like:
>  MyModel.objects.filter(key_to_mymodel2 = MyModel2.objects.all()))
> This query produce SQL:
> SELECT * FROM `test_mymodel` WHERE key_to_mymodel2_id =(select `id`
> from `test_mymodel2`)
>
> It works fine on SQLLite, but in MySQL it produce error:
> OperationalError: (1242, 'Subquery returns more than 1 row')
> MySQL to work need query:
> SELECT * FROM `test_mymodel` WHERE key_to_mymodel2_id = ANY (select
> `id` from `test_mymodel2`)


With the same data?  It seems like a legitimate error unless test_mymodel2
has just one row, which would be odd.  I would expect the subquery to have a
WHERE or LIMIT clause that would restrict it to returning a single row, to
be useful.

If you really expect the subquery to return multiple rows, perhaps you mean
something like this:

SELECT * FROM `test_mymodel` t1, (SELECT `id` FROM `test_mymodel2`) t2 WHERE
t1.id = t2.id

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.


Reply via email to