Question

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

Was it helpful?

Solution

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)');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top