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 8707607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:54:44+00:00 2026-06-13T03:54:44+00:00

I have a problem with a drupal db_select. Here is my code : $query

  • 0

I have a problem with a drupal db_select.

Here is my code :

    $query = db_select('node', 'n');
    $query->addField('n', 'nid', 'nid');
    $query->addField('cfs', 'entity_id', 'feature_support_id');
    $query->addField('fpffs', 'entity_id', 'parent_feature_support_id');
    $query->addField('cfsfc', 'feature_support_compared_target_id', 'feature_support_compared');
    $query->addField('fpffsfc', 'feature_support_compared_target_id', 'parent_feature_support_compared');
    //Get feature_support of the feature
    $query->join('field_data_feature_support_feature', 'cfs', 'n.nid = cfs.feature_support_feature_target_id');
    $query->join('field_data_feature_support_compared', 'cfsfc', 'cfs.entity_id = cfsfc.entity_id');
    //Get parent feature_support through feature
    $query->join('field_data_feature_parent_feature', 'fp', 'n.nid = fp.entity_id');
    $query->join('field_data_feature_support_feature', 'fpffs', 'fp.feature_parent_feature_target_id = fpffs.feature_support_feature_target_id');
    $query->join('field_data_feature_support_compared', 'fpffsfc', 'fpffs.entity_id = fpffsfc.entity_id');
    $query->condition('n.nid', $node_revision->nid, '=');
    $query->condition('cfsfc.feature_support_compared_target_id', 'fpffsfc.feature_support_compared_target_id', '=');
    $result = $query->execute();

In DB my request should be

SELECT n.nid AS nid, cfs.entity_id AS feature_support_id, fpffs.entity_id AS parent_feature_support_id, cfsfc.feature_support_compared_target_id AS feature_support_compared, fpffsfc.feature_support_compared_target_id AS parent_feature_support_compared
FROM node n
INNER JOIN field_data_feature_support_feature cfs ON n.nid = cfs.feature_support_feature_target_id
INNER JOIN field_data_feature_support_compared cfsfc ON cfs.entity_id = cfsfc.entity_id
INNER JOIN field_data_feature_parent_feature fp ON n.nid = fp.entity_id
INNER JOIN field_data_feature_support_feature fpffs ON fp.feature_parent_feature_target_id = fpffs.feature_support_feature_target_id
INNER JOIN field_data_feature_support_compared fpffsfc ON fpffs.entity_id = fpffsfc.entity_id
WHERE  (n.nid = '9') AND (cfsfc.feature_support_compared_target_id = fpffsfc.feature_support_compared_target_id)

This request work when I try it in phpmyadmin, but instead in mysql log I have

SELECT n.nid AS nid, cfs.entity_id AS feature_support_id, fpffs.entity_id AS parent_feature_support_id, cfsfc.feature_support_compared_target_id AS feature_support_compared, fpffsfc.feature_support_compared_target_id AS parent_feature_support_compared
FROM node n
INNER JOIN field_data_feature_support_feature cfs ON n.nid = cfs.feature_support_feature_target_id
INNER JOIN field_data_feature_support_compared cfsfc ON cfs.entity_id = cfsfc.entity_id
INNER JOIN field_data_feature_parent_feature fp ON n.nid = fp.entity_id
INNER JOIN field_data_feature_support_feature fpffs ON fp.feature_parent_feature_target_id = fpffs.feature_support_feature_target_id
INNER JOIN field_data_feature_support_compared fpffsfc ON fpffs.entity_id = fpffsfc.entity_id
WHERE  (n.nid = '9') AND (cfsfc.feature_support_compared_target_id = 'fpffsfc.feature_support_compared_target_id')

See at the end, in the WHERE, there is single quote around ‘fpffsfc.feature_support_compared_target_id’ which should not be there.

It’s obviously because the second argument of ->condition seems only accept variable. Anyone know how I can make a condition with two db fields with db_select?

Thanks for any help you can bring me.

  • 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-13T03:54:45+00:00Added an answer on June 13, 2026 at 3:54 am

    Use $query->where($snippet, $args = array());

    $query->where('cfsfc.feature_support_compared_target_id = fpffsfc.feature_support_compared_target_id');  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this sql code in Drupal: $query = db_query('SELECT wpv.nid, n.title, AVG(vote)
I have an odd problem in my jQuery code that loads in Drupal 7
I have the following problem in Drupal 6 with CCK: user1 creates node 1
I have a problem with Drupal uploads path when in a multi language site.
I have a problem with the following implementation of hook_cron in Drupal 6.1.3. The
I have problem with my query on C, I’m using the oci8 driver. This
I have some problem in drupal registration page. I want to change whole user
I have a problem with Drupal: I build sites that have a protected area
I'm having a problem working out how drupal structures content. I have a content
I'm new to Drupal & PHP. I have a similar problem to this unanswered

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.