Yii Framework Forum: Condition Breaks My Subquery By Adding One Brace Too Much? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Condition Breaks My Subquery By Adding One Brace Too Much? Rate Topic: -----

#1 User is offline   Jonas 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 18-May 11
  • Location:Switzerland

Posted 22 September 2013 - 03:24 AM

Hi all,

I have this query:
$currentIssue = Issue::model()->find(array(
   'condition'=>'number = (SELECT max(number) FROM issue))'
));


Which looks good to me and works in phpMyAdmin.

But Yii gives me this error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1. The SQL statement executed was: SELECT * FROM `issue` `t` WHERE number = (SELECT max(number) FROM issue)) LIMIT 1

Somehow it is adding an additional brace at the end of the subquery.

When I remove the last brace from the condition (which looks wrong to me) the query is working. Can anyone explain to me why this is?

Thanks
Jonas
My Blog: jonaszumkehr.ch
0

#2 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 622
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 22 September 2013 - 04:21 AM

Wait, in the code you posted there are two opening braces and three closing.
Don't be a dick.
0

#3 User is offline   Jonas 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 18-May 11
  • Location:Switzerland

Posted 22 September 2013 - 04:47 AM

Oh boy... I just didn't see it... Thanks for pointing out this obvious mistake.
My Blog: jonaszumkehr.ch
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users