0

need a bit of help please, when i write my query like this it works fine

    $query = db_query('select * from form_submissions where address in (select address from form_submissions group by address having count(address) > 1 ');
    $submissions = $query->execute();

but when i write it with drupal it should work like this? but it dont

    $query = db_select('form_submissions', 'sfs')->fields('sfs', array());
    $subquery = db_select('form_submissions', '')->fields('address', array())->groupBy('address')->having('count(address) > 1');
    $query->condition('address', $subquery, 'in');

    $submissions = $query->execute();

can someone see what im doing wrong?

  • i solved it needed to put address in array – lukee Dec 11 '18 at 10:52
0
    $query = db_select('form_submissions', 'sfs')->fields('sfs', array());
    $subquery = db_select('form_submissions', 'sfs')->fields('sfs', array('address'))->groupBy('address')->having('count(address) > 1');
    $query->condition('address', $subquery, 'in');

    $submissions = $query->execute();
0

Please try following code:

$query = db_select('form_submissions', 'sfs')
    ->fields('sfs');
$subquery = db_select('form_submissions', 'subsfs')
    ->fields('subsfs', array('address'))
    ->groupBy('subsfs.address')
    ->addExpression('COUNT(subsfs.address)', 'countAddress')
    ->havingCondition('countAddress', 1, '>');

$query->condition('sfs.address', $subquery, 'IN');

    $submissions = $query->execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.