views:

231

answers:

0

Hi,

I have a photos table where users can have multiple photos.

I'm trying to create the following query:

$q = Doctrine_Query::create()
   ->update('Photo p')
   ->set('p.photo_type', 1)
   ->where('p.user_id = ?', $id)
   ->andWhere('p.date_added = (SELECT MIN(p.date_added) FROM Photo p WHERE p.user_id = ?)', $id)

The idea is to set the "photo_type" to 1 for that specific photo of this user that has the minimum date added (earliest photo).

I just can't seem to get the syntax right. Can someone point me in the right direction?

Thank you.

EDIT:

It seems I'm trying to do something that can't be done, as per the answer to this question (http://stackoverflow.com/questions/45494/sql-delete-cant-specify-target-table-for-update-in-from-clause). This question can be closed.