0

I would like to create a sql query in Zend Framework in the Abstract.php or in model? but I have a hard time figure out how to do it. I am new in zend framework.

The query that I want to create looks like that:

delete from users where id not in(select * from(select min(n.id)from users n group by n.email)x);

But in zend:

$results = $db->query('delete
                from users
                where id not in(
                    select * from(
                        min(n.id)
                        from users n
                        group by n.email
                )x)');

Look like the $db got a undefined variable, what kind of database function should the db call? My database is being call in the application.ini

3
  • 1
    That's not even the slightest bit valid PHP code. Look at stackoverflow.com/a/5380654/1902010 for something similar to what you're trying to do. Commented Feb 11, 2013 at 21:53
  • I'd imagine you change select() to delete(), but you'd want to learn PHP and read the documentation before you go doing destructive changes to data like that. Commented Feb 11, 2013 at 22:08
  • Which database adapter are you using? It should be set in your ini file. Commented Feb 12, 2013 at 1:41

1 Answer 1

2

you have to write this syntex for executing your custom query..

$db->getAdapter()->query('delete
                from users
                where id not in(
                    select * from(
                        min(n.id)
                        from users n
                        group by n.email
                )x)');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.