Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8084949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:57:02+00:00 2026-06-05T17:57:02+00:00

I am trying to code the following query using Zend_Db api’s: select * from

  • 0

I am trying to code the following query using Zend_Db api’s:

select * from tableA where id not in (select pid from tableB where x =46 and y='participated');

I wrote the following code to get this to work:

First I am getting the list of pid’s in array format from tableB:

    $select = $this->select()
    ->from(array('tb' =>'tableB'), array('mylist' => new Zend_Db_Expr('group_concat(tb.pid)' )))
    ->where('x = ?', $xval) //$xval is coming as 46
    ->where('type = ?', 'participated');

    $result = $this->getAdapter()->fetchAll($select);
    error_log("Result of query1 is " . print_r($result, true));

    //Convert to array
    $mylistArr = preg_split('/,/' , $result[0]['mylist'], PREG_SPLIT_NO_EMPTY);
    error_log("value of mylistArr is " . print_r($mylistArr, true));


    //Now get the results from tableA
    $selectta = $this->select()
    ->setIntegrityCheck(false)
    ->from(array('ta' => 'tableA'), array('ta.id', 'ta.first_name', 'ta.last_name'))
    ->where('ta.id not in (?)', $mylistArr[0]);

    $result = $this->fetchAll($selectta);
    error_log("db query result is " . print_r($result, true));

Now, the problem is this:
The final query being formed is

SELECT `ta`.`id`, `ta`.`first_name`, `ta`.`last_name` FROM `tableA` AS `ta` WHERE (ta.id not in ('197,198,199,200,106,201,202,204,203,205'))

However, I want the query to look as follows (that is, the list of id’s from tableB should not be enclosed in inverted commas):

SELECT `ta`.`id`, `ta`.`first_name`, `ta`.`last_name` FROM `tableA` AS `ta` WHERE (ta.id not in (197,198,199,200,106,201,202,204,203,205))

The reason is that when inverted commas are being passed in the IN clause, only the first id ie 197 is being picked up to filter the results.

Any help is really appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:57:04+00:00Added an answer on June 5, 2026 at 5:57 pm

    Instead of using preg_split, I needed to use explode and convert the comma delimited string to an array of id’s that could be passed to the where IN clause.

    The following is the final implementation I did:

     $select = $this->select()
        ->from(array('tb' =>'tableB'), array('mylist' => new Zend_Db_Expr('group_concat(tb.pid)' )))
        ->where('x = ?', $xval) //$xval is coming as 46
        ->where('type = ?', 'participated');
    
        $result = $this->getAdapter()->fetchAll($select);
        error_log("Result of query1 is " . print_r($result, true));
    
        //Convert to array
        $mylistArr = explode(",", $result[0]['mylist']);
        error_log("value of mylistArr is " . print_r($mylistArr, true));
    
    
        //Now get the results from tableA
        $selectta = $this->select()
        ->setIntegrityCheck(false)
        ->from(array('ta' => 'tableA'), array('ta.id', 'ta.first_name', 'ta.last_name'))
        ->where('ta.id not in (?)', $mylistArr);
    
        $result = $this->fetchAll($selectta);
        error_log("db query result is " . print_r($result, true));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to code the following HQL query using the Criteria API: var userList
I'm using the following code to run a passthrough query. I'm trying to run
I'm trying to execute a query in PostgreSQL using the following code. It's written
Using PostgreSQL 8.4, I'm trying to put together the following query: SELECT (field_a +
I'm trying the following code http://code.google.com/apis/ajax/playground/#change_the_playing_video It works well when runned from the playground
I'm trying the following code to execute a search and it's not working. On
I found the following code example (from Telerik ) that I'm trying to understand.
I'm using LINQ-to-Entities. Using the following query: var x = from u in context.Users
I have the following query: select id from table1 where some_func(?) = 1; where
I'm trying to use Entity Framework to query database and I have following code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.